各位大大,使用Maven开发时hibernate的映射文件和Spring的整合文件在maven的一子模块A中,是jar文件,另一个maven的web模块B读取A的model一直抱notMaping..可是在A模块能单独load出该实体,同样的代码在A中能正常运行,在B中就报org.hibernate.MappingException: Unknown entity
A项目的Spring 配置文件中如下
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<context:annotation-config></context:annotation-config>
<context:component-scan base-package="com.yolipai"></context:component-scan>
<!-- 开启CGLIB针对类实现代理 -->
<aop:aspectj-autoproxy proxy-target-class="true"/>
<!-- Spring集成Hibernate -->
<!-- 1.数据库连接配置(增加了dhcp连接池连接) -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!-- 2.指定数据库属性配置文件位置-->
<context:property-placeholder location="classpath*:jdbc.properties"/>
<!-- 3.配置Hibernate的SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!-- 4.设置Annotations的方式扫描的包 -->
<property name="packagesToScan">
<value>com.yolipai</value>
</property>
<!-- 扫描配置文件方式 -->
<!-- <property name="mappingLocations">
<value>classpath*:com/yolipai/**/*.hbm.xml</value>
</property> -->
<!-- Jar包扫描 -->
<!-- <property name="mappingJarLocations">
<list>
<value>WEB-INF/lib/yolipai-core-0.0.1-SNAPSHOT.jar</value>
</list>
</property>
<property name="mappingLocations">
<list>
<value>classpath*:com/yolipai/**/*.hbm.xml</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>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<!-- 5.Spring事务配置 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<aop:config>
<aop:pointcut id="allMethod"
expression="execution(* com.yolipai.*..dao.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="allMethod"/>
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- 6.配置事务加在哪个方法中 -->
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<!-- 开启HibernateTemplate,并且为其注入SessionFactory
使用HibernateTemplate不太方便的就是要获取session得通过getSessionFactory()方法获取 -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</beans>
在B项目中spring mvc的配置文件中使用<import resource="classpath*:beans.xml" />引用了A模块的配置文件,出现上述问题,怎么解决?谢谢!
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
为什么把映射jar文件的entity配置给注释掉? 打开jar文件的entity映射试试
为什么把映射jar文件的entity配置给注释掉? 打开jar文件的entity映射试试