maven数据源作为模块后加载hibernate模型类

来源:互联网 发布:淘宝卖耐克 编辑:程序博客网 时间:2024/06/06 17:23

最近在弄maven,将hibernate加载的实体类,单独作为模块,打成jar后。web工程怎么也加载不了hibernate里面的模型类。

我的配置最初是这样的

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
p:dataSource-ref="dataSource"
p:mappingDirectoryLocations="classpath:/com/......../model">
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
            </props>
        </property>
</bean>

后来发现原因是,web工程没法通过classpath或者sources加载jar中的类。

最终改成

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
p:dataSource-ref="dataSource">
<property name="packagesToScan">
<list>
<value>com........model</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
</bean>

一切问题搞定!

0 0
原创粉丝点击