I'm developing a Spring 3.2.1 based webapp (RestFull Services) to be deployed on a Tomcat 6 server. Because of Jpa, Transaction and features from other custom dependency projects I have to enable loadTime weaving. To do so first I configured my context.xml in app /META-INF adding:
<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>
Then I put spring-instrument-3.2.1.RELEASE.jar and spring-instrument-tomcat-3.2.1.RELEASE.jar in my tomcat/lib folder.
And configured the web.xml to user annotationBasedConfiguration
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>local</param-value>
</context-param>
<context-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
com.xxx.yyy.spring.SpringConfiguration
com.xxx.yyy.configuration.spring.WebSpringConfiguration
</param-value>
</context-param>
<!--Spring -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Webapp uses code configuration with no XML so I created an @Configuration annotate classes like:
@Configuration
@Profile("local")
@EnableLoadTimeWeaving
@EnableSpringConfigured
@EnableTransactionManagement(proxyTargetClass = true)
@Import(value = {DataSourceLocal.class,HibernateConfigurationLocal.class})
@ImportResource({"classpath:/database-context.xml"}) // context from imported jar library
@ComponentScan(basePackages = {"com.xxx.yyy","com.xxx.yyy.configuration"})
@EnableJpaRepositories(basePackages = {"com.xxx.yyy.repositories"})
public class SpringConfiguration
{
[...]
}
When I try to start the application I recieve the error
ERROR | ContextLoader - Context initialization failed
java.lang.IllegalStateException: No LoadTimeWeaver available
So at first it seemed to me that LoadTimeWeaving was not properly configured but after a day trying any possible workaround I still haven't found a solution.
The only strange thing I can see is that line of log:
Overriding bean definition for bean 'loadTimeWeaver': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.context.annotation.LoadTimeWeavingConfiguration; factoryMethodName=loadTimeWeaver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/context/annotation/LoadTimeWeavingConfiguration.class]] with [Generic bean: class [org.springframework.context.weaving.DefaultContextLoadTimeWeaver]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null;
Which it seems to me like 2 different bean with the same name ("LoadTimeWeaver" ??) were created in the app context with different definitions and that those two bean are conflicting at some level.
Is it possible that the weaver create using context:load-time-weaver (which is present in a context file loaded from an imported jar) and the one created using @EnableLoadTimeWeaving in my new context are clashing somehow? Is there a way to override one of the two using only the last one?