Tomcat下使用Spring + JPA 需要注意的问题

Tomcat默认的类加载器不支持类转换,所以需要使用自定义的类加载器,具体操作步骤如下:

1.在LocalContainerEntityManagerFactoryBean中,设置loadTimeWeaver属性

 <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="persistenceXmlLocation"
                  value="classpath:META-INF/persistence.xml" />
        <property name="loadTimeWeaver">
            <bean class="org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver"/>
        </property>
    </bean>
2.在WEB应用的META-INF/context.xml文件中,使用自定义类加载器

<Context antiJARLocking="true" path="/web">
    <!--
        由于需要在Tomcat下使用JPA,并且和Spring进行集成,所以需要使用自定义的类加载器
        复制spring-instrument-tomcat.jar文件到${CATALINA_HOME}/lib目录下
    -->
    <Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>
</Context>
3.下载spring-instrument-tomcat-xxxxx.jar
最好使用和Spring版本相同的jar包,根据使用不同版本的Spring,可以在在Maven存储库中搜索:
http://search.maven.org/#search|ga|1|spring-instrument-tomcat
我使用的是spring-instrument-tomcat-3.2.3.RELEASE.jar,下载了文件以后,把jar文件复制到tomcat的lib



转自:http://blog.163.com/java_star/blog/static/1177148052013627389268/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值