How to use JPA in spring sample petclinic?
I am learning spring samples. In the petcli开发者_开发技巧nic project, by default it uses jdbc. I change the following line to jpa, and can't run it anymore
/WEB-INF/spring/applicationContext-jpa.xml
Here is the error message:
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
at org.springframework.context.weaving.DefaultContextLoadTimeWeaver.setBeanClassLoader(DefaultContextLoadTimeWeaver.java:83)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1418)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1389)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512)
... 35 more
Any response would be very helpful.
The default Tomcat class loader does not support class transformation required for Load-Time Weaving. You need to use the one provided by Spring.
First, copy org.springframework.instrument-3.0.0.RELEASE.jar
to the lib
folder of your tomcat installation
Then modify the src/main/webapp/META-INF/context.xml
and uncomment the following line:
<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>
Or you could get rid of the LTW and use Hibernate as JPA provider. See the related question below.
See also
- Spring Load-time Weaving on Tomcat: Does It Really Work?
Related question
- How to run Spring 3.0 PetClinic in tomcat with Hibernate backed JPA
References
- 3.12 Registering a LoadTimeWeaver
- 7.8.1 Using AspectJ to dependency inject domain objects with Spring
- 7.8.4 Load-time weaving with AspectJ in the Spring Framework
精彩评论