0

I have a problem with this linkage error, we have projects with the same code and works :

this.plateformTransactionManager = new DataSourceTransactionManager();
this.plateformTransactionManager.setDataSource(dataSource);
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
TransactionStatus status = plateformTransactionManager.getTransaction(def);

Stack trace at runtime :

java.lang.LinkageError: loader constraint violation: when resolving method org.springframework.jdbc.datasource.DataSourceTransactionManager.getTransaction(Lorg/springframework/transaction/TransactionDefinition;)  Lorg/springframework/transaction/TransactionStatus;" the class loader    (instance of  org/apache/catalina/loader/WebappClassLoader) of the current class, com/as24/referentiel/daos/ExternalUserDAO, and the class loader (instance of  rg/apache/catalina/loader/StandardClassLoader) for resolved class,  org/springframework/jdbc/datasource/DataSourceTransactionManager, have different Class Objects for the type org/springframework/transaction/TransactionDefinition used in the Signature

I read it's a maven dependancies error but we used Spring only on version 3.0.7.REALEASE

I don't find any soutions on the web ...

4

1 回答 1

0

This is a problem of shared libraries between between server and web application.

In java a class is identified by its name (including package name) and its class loader (which loaded it). So if you have the same MyBean.class inside web application WEB-INF/classes and also inside ${catalina.home}/lib, these will be viewed as two different classes (i.e. myBean instanceof MyBean == false). When JVM approaches situation where some class is using class XYZ in its method signatures and XYZ is loaded by a different classloader than a class XYZ known by the current class loader, then LinkageError is raised.


You problem is that you have Spring dependencies (at least spring-tx) on the shared / system class loader and also within web application dependencies.

To solve your issue you need to do one of the following:

  • remove Spring dependencies from server class-loaders
  • remove duplicate dependency from the web application (mark it as provided dependency in POM)
  • add duplicate dependencies on endorsed class-loader (by that web application class-loader will ignore the web application dependency).
于 2013-07-16T09:22:34.040 回答