您可以在 application context.xml 文件中执行类似操作来扫描所有注释类 -
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="lobHandler" ref="lobHandler"/>
<property name="packagesToScan">
<list>
<value>com.idc.scd.domain</value>
<value>com.idc.scd.domain.dropdown</value>
<value>com.idc.scd.domain.external</value>
<value>com.idc.scd.domain.pk</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key="hibernate.use_sql_comments">${hibernate.use_sql_comments}</prop>
<prop key="hbm2ddl.auto">validate</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.connection.release_mode">after_statement</prop>
<prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProvider</prop>
<prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
<prop key="hibernate.cache.use_structured_entries">${hibernate.cache.use_structured_entries}</prop>
<prop key="hibernate.jdbc.fetch_size">${hibernate.jdbc.fetch_size}</prop>
</props>
</property>
</bean>