在我的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中,所以现在,com.mycompany.sample.domain包中的所有使用@Entity注释的类都将被自动提取.