Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
255 views
in Technique[技术] by (71.8m points)

java - How to run Spring 3.0 PetClinic in tomcat with Hibernate backed JPA

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...