如何使用Hibernate支持的JPA在tomcat中运行Spring 3.0 PetClinic [英] How to run Spring 3.0 PetClinic in tomcat with Hibernate backed JPA

查看:99
本文介绍了如何使用Hibernate支持的JPA在tomcat中运行Spring 3.0 PetClinic的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,这可能应该是世界上最简单的事情,但我一直在尝试整个一天,但它仍然无法正常工作。任何帮助都会受到高度赞赏!



编辑:正确的程序请参阅帕斯卡的回答。

我的错误的(因为我没有禁用LoadTimeWeaving)过程留作参考..:



我做了什么:


  1. 已下载的Tomcat 6.0.26& Spring 3.0.1

  2. https:/下载PetClinic /src.springframework.org/svn/spring-samples/petclinic

  3. 建造&部署petclinic.war。使用默认的JDBC持久性保持良好。

  4. 将Hibernate 。

  5. 编辑webapps / WEB-INF / web.xml并将applicationContext-jdbc.xml中的 context-param 更改为applicationContext-jpa .xml

  6. 将Spring 3.0.1发行版中的所有内容复制到TOMCAT_HOME / lib中。

  7. 推出tomcat。看到



    由于:java.lang.IllegalStateException:ClassLoader [org.apache.catalina.loader.WebappClassLoader]没有提供'addTransformer(ClassFileTransformer)'方法。使用Spring的代理指定自定义的LoadTimeWeaver或启动Java虚拟机:-javaagent:spring-agent.jar


  8. 未注释的行< Loader loaderClass =org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader/> 在webapps / META-INF / context.xml中。


  9. 同样的错误。将该行添加到TOMCAT_HOME / context.xml中
  10. 部署时没有错误。但是,当我执行某些操作时,它会发出一个错误消息,指出在org.hibernate.ejb上的javax / transaction / SystemException异常:

    java.lang.NoClassDefFoundError .EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:39)



    11.将javax.transaction的范围从测试更改为默认值(仅删除测试) ,如脚手所示。

    12.跑得好!谢谢!

  11. p>


    1. 获取Tomcat 6.0.26
    2. 签出petclinic样本:

        svn co https://src.springframework.org/svn/spring-samples/petclinic/trunk/ petclinic 

    3. cd 进入petclinic目录


    4. 修改 src / main / webapp / WEB-INF / spring / applicationContext-jpa.xml 使用Hibernate:


    5. 修改 src / main /webapp/WEB-INF/web.xml 来使用 applicationContext-jpa.xml

    6. 在战争中修改 pom.xml 以捆绑 jta.jar (正如@skaffman指出的那样):

       < dependency> 
      < groupId> javax.transaction< / groupId>
      < artifactId> com.springsource.javax.transaction< / artifactId>
      < version> 1.1.0< / version>
      <! - scope> test< / scope - >
      < /依赖关系>


    7. 建立战争

       mvn install 


    8. 将其部署到Tomcat

        cp target / petclinic.war $ TOMCAT_HOME / webapps 


    9. 浏览

        http:// localhost:8080 / petclinic 



    OK, this probably is supposed to be the easiest thing in the world, but I've been trying for the entire day, and it's still not working.. Any help is highly appreciated!

    EDIT: For the correct procedure, please see Pascal's answer.

    My wrong (since I did not disabled LoadTimeWeaving) procedure is left for reference..:

    What I did:

    1. Downloaded Tomcat 6.0.26 & Spring 3.0.1
    2. Downloaded PetClinic from https://src.springframework.org/svn/spring-samples/petclinic
    3. Built & deployed petclinic.war. Ran fine with default JDBC persistence.
    4. Edited webapps/WEB-INF/spring/applicationContext-jpa.xml and set jpaVendorAdaptor to Hibernate.
    5. Edited webapps/WEB-INF/web.xml and changed context-param from applicationContext-jdbc.xml to applicationContext-jpa.xml
    6. Copied everything in the Spring 3.0.1 distribution to TOMCAT_HOME/lib.
    7. Launched tomcat. Saw

      Caused by: java.lang.IllegalStateException: ClassLoader [org.apache.catalina.loader.WebappClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:spring-agent.jar

    8. Uncommented line <Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/> in webapps/META-INF/context.xml.

    9. Same error. Added that line to TOMCAT_HOME/context.xml
    10. Deployed without error. However, when I do something it will issue an error saying

      java.lang.NoClassDefFoundError: javax/transaction/SystemException at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:39)

      11.Changed scope of javax.transaction from test to default (just deleted test), as suggested by scaffman.

      12.Runs fine!! Thank you!

    解决方案

    Ok, here is what I did:

    1. Get Tomcat 6.0.26
    2. Checkout the petclinic sample:

      svn co https://src.springframework.org/svn/spring-samples/petclinic/trunk/ petclinic
      

    3. cd into the petclinic directory

    4. Modify src/main/webapp/WEB-INF/spring/applicationContext-jpa.xml to use Hibernate:
    5. Modify the src/main/webapp/WEB-INF/web.xml to use the applicationContext-jpa.xml
    6. Modify the pom.xml to bundle jta.jar in the war (as pointed out by @skaffman):

      <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>com.springsource.javax.transaction</artifactId>
        <version>1.1.0</version>
        <!--scope>test</scope-->
      </dependency>
      

    7. Build the war

      mvn install
      

    8. Deploy it to Tomcat

      cp target/petclinic.war $TOMCAT_HOME/webapps
      

    9. Browse

      http://localhost:8080/petclinic
      

    这篇关于如何使用Hibernate支持的JPA在tomcat中运行Spring 3.0 PetClinic的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆