Spring automatically scans entities and loads configuration implementations

Source: Internet
Author: User

Http://www.blogjava.net/sean/archive/2009/01/29/252685.html


[Tips] Packagestoscan of new features of Spring 2.5.6Posted on 2009-01-29 02:59 Laogao Reading (3790) Comments (0) Edit Favorites categories: on Java
If you use the earlier version of spring, you configure Hibernate object relational mappings just by using annotation annotations rather than traditional XML methods. So when configuring Sessionfactory through Org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean, you must be annotatedclasses , Annotatedpackages has an inability to say the feeling of chest tightness, so high configuration of spring, how in this a small link can not do more flexible, must be a handwritten class path.

It is estimated that a lot of people have chosen to inherit a custom subclass from Annotationsessionfactorybean, implement the scan logic themselves, and find the @entity annotated class list configuration.

One of the less noticeable improvements in Spring 2.5.6 is the addition of a new approach to Annotationsessionfactorybean:
Setpackagestoscan (string[] packagestoscan)

With this approach, we no longer need to implement the entity class scan by ourselves, directly in the spring configuration file Annotationsessionfactorybean This section to add a property similar to the following ( Suppose you need to load the entity class that contains the package name match this string "Com.**.bo"):
< property name = "Packagestoscan" value = "Com.**.bo"/>
You can also specify more than 1 matching strings in the form of a list, such as:
< property name = "Packagestoscan" >
< list >
< value > Com.abc.core.bo </value >
< value > Com.abc.auditing.bo </value >
</list >
</Property >


Example:

<property name= "Packagestoscan" >
<list>
<value>com.def.modules.*.bean</value>
<value>com.abc.**.bean</value>
</list>
</property>




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.