1

我正在开发一个基于 Spring 3.2.1 的 webapp (RestFull Services) 以部署在 Tomcat 6 服务器上。由于来自其他自定义依赖项项目的 Jpa、事务和功能,我必须启用 loadTime 编织。为此,我首先在 app /META-INF 中配置了我的 context.xml,并添加了:

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

然后我将spring-instrument-3.2.1.RELEASE.jarspring-instrument-tomcat-3.2.1.RELEASE.jar放在我的 tomcat/lib 文件夹中。

并将 web.xml 配置为用户 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 使用没有 XML 的代码配置,所以我创建了一个 @Configuration 注释类,例如:

@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
{ 
[...]
}

当我尝试启动应用程序时,我收到错误

ERROR | ContextLoader - Context initialization failed
java.lang.IllegalStateException: No LoadTimeWeaver available

因此,起初在我看来,LoadTimeWeaving 配置不正确,但在尝试任何可能的解决方法一天后,我仍然没有找到解决方案。

我能看到的唯一奇怪的事情是那一行日志:

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;

在我看来,在应用程序上下文中创建了两个具有相同名称(“LoadTimeWeaver”??)的不同 bean,具有不同的定义,并且这两个 bean 在某种程度上存在冲突。

织布工是否有可能使用 context:load-time-weaver 创建(它存在于从导入的 jar 加载的上下文文件中)和在我的新上下文中使用 @EnableLoadTimeWeaving 创建的那个在某种程度上发生了冲突?有没有办法只使用最后一个来覆盖两者之一?

4

0 回答 0