The project I am working on has a similar structure for the DAOs
to the one bellow:
/**
* Base DAO class
*/
@Transactional
public class JPABase {
@PersistenceContext
private EntityManager entityManager;
public void persist(Object entity) {
entityManager.persist(entity);
}
//some more methods in here
}
and
/**
* Generic DAO class implementation
*/
@Transactional
public abstract class GenericDao extends JpaBase {
//some methods in here
}
and
/**
* Specialized DAO class
*/
@Repository
@Transactional
public class PersonDao extends GenericDao {
//some methods in here
}
Until now, the project used compile time weaving, but the configuration has changed to use <context:load-time-weaver/>
with -javaagent:/opt/tomcat7-1/lib/spring-instrument.jar
.
Since this change has been applied, the JpaBase
's and GenericDao
's @Transactional
annotations are not weaved anymore. Each time a service class calls the persist
method on a PersonDao
object, no transaction is started.
Noteworthy:
PersonDao
are weaved correctly, but the ones inherited (e.g. persist(Object entity)
) are NOT weaved.Compile time weaving and load time weaving are supposed to do the same thing, just at different moments in time. Why has the weaving behaviour changed?
Tomcat default classlLoader
is WebappClassLoader
, but you need `TomcatInstrumentableClassLoader.
There are two solutions:
- Modify WebappLoader.class
Change WebappLoader.java
private String loaderClass = "org.apache.catalina.loader.WebappClassLoader";
Replace:
private String loaderClass = "org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader";
Compile it and replaced the class file(catalina.jar), then it works.
Here is required dependency jars: catalina.jar
,tomcat-coyote.jar
,tomcat-util.jar(/bin)
,tomcat-juli.jar
- Modify context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>
</Context>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With