【问题标题】:Spring SessionFactory creation domain objects auto scanningSpring SessionFactory 创建域对象自动扫描
【发布时间】:2011-12-21 16:28:47
【问题描述】:

在我的 spring dao 配置 xml 中,我目前必须手动列出域类名称。有没有什么办法可以自动化这个过程,以消除在创建新域类时手动列出域类的需要?

为了更好地了解我想要做什么,使用类似于组件扫描或类似的东西

当前代码

<bean id="daoSessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="applicationDataSource" />
    <property name="annotatedClasses">
        <list>
            <value>com.greenwhich.application.domain.Driver</value>
            <value>com.greenwhich.application.domain.DriverRealTimeCurrentLocation</value>
            <value>com.greenwhich.application.domain.Journey</value>
            <value>com.greenwhich.application.domain.Customer</value>
            <value>com.greenwhich.application.domain.SystemConstants</value>
            <value>com.greenwhich.application.domain.DriverRequest</value>              
            <value>com.greenwhich.application.domain.Account</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
        </props>
    </property>
</bean>

我只要求自动检测“annotatedClasses”属性下的值

有什么方法可以实现吗?到目前为止,我已经尝试在“annotatedClasses”属性中插入组件扫描,以搜索不起作用的“Entity”注释

非常感谢任何帮助

【问题讨论】:

    标签: java hibernate spring dependency-injection


    【解决方案1】:

    您应该能够将 annotatedClasses 属性替换为:

    <property name="packagesToScan" value="com.greenwhich.application.domain" />
    

    作为会话工厂配置的一部分。

    【讨论】:

      猜你喜欢
      • 2016-05-16
      • 1970-01-01
      • 1970-01-01
      • 2018-07-05
      • 1970-01-01
      • 2018-11-06
      • 2021-01-22
      • 1970-01-01
      • 2020-04-21
      相关资源
      最近更新 更多