在我的applicationContext.xml中,这就是将xml映射到POJO的方式。如何将目录映射到类文件而无需创建xml?
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="mappingResources"> <list> <value>com/custompackage/custom/spi/hibernate3/HibernateCurrentStep.hbm.xml</value> <value>com/custompackage/custom/spi/hibernate3/HibernateHistoryStep.hbm.xml</value> <value>com/custompackage/custom/spi/hibernate3/HibernatecustomEntry.hbm.xml</value> <value>user/custom/hibernate3/PropertySetItemImpl.hbm.xml</value> <value>com/custompackage/user/provider/hibernate3/user/impl/HibernateGroupImpl.hbm.xml</value> <value>com/custompackage/user/provider/hibernate3/user/impl/HibernateUserImpl.hbm.xml</value> </list> </property> <property name="hibernateProperties"> ..... </property> <property name="dataSource"> <ref bean="dataSource" /> </property> </bean>
您可以通过转换进一步简化操作
<property name="annotatedClasses"> <list> <value>com.mycompany.sample.domain.Order</value> <value>com.mycompany.sample.domain.LineItem</value> ... </list> </property>
至
<property name="packagesToScan" value="com.mycompany.sample.domain" />
AnnotationSessionFactoryBean现在您@Entity的com.mycompany.sample.domain包中所有带有注释的类都将自动被拾取。
AnnotationSessionFactoryBean
@Entity
com.mycompany.sample.domain