How to use jpa in spring lapel sample?

I am studying spring samples. In a loop project, jdbc is used by default. I change the next line to jpa and can no longer run it

/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 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 answer would be very helpful.

+4
source share
1 answer

By default, the Tomcat class loader does not support the class conversion required by Load-Time Weaving. You should 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 change src/main/webapp/META-INF/context.xml and uncomment the following line:

 <Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/> 

Or you can get rid of LTW and use Hibernate as a JPA provider. See the related question below.

see also

Related question

References

+7
source

All Articles