我尝试在我的项目中使用 spring weblogic LTW 来做一些 aop 的东西。我的项目是一个简单的 webapp servlet2.5,使用 spring mvc 3.2.6,在 weblogic 10.0 上运行。我在 web.xml 中有以下应用程序级别的配置设置
@Configuration @EnableLoadTimeWeaving public class AppConfig { } @Configuration @EnableTransactionManagement @ComponentScan(basePackages = { "com.blabla.model" }) public class CoreConfig { }
我的 web.xml 中还有一个 mvc 级别的配置设置
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = { "com.blabla.controller" })
public class MVCConfig extends WebMvcConfigurerAdapter {
}
这是我的简化 web.xml
<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>AppConfig,CoreConfig
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>MVCConfig
</param-value>
</init-param>
<init-param>
<param-name>wl-dispatch-policy</param-name>
<param-value>RestWorkManager</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
所以发生的事情是,MVCConfig
它的扫描组件都是由 LTW 编织的,效果很好。但是LTW 并没有接收到CoreConfig
它扫描的组件(所有 DAO) 。
我猜CoreConfig
andAppConfig
处于同一级别,所以当AppConfig
andCoreConfig
被加载时,LTW 还没有被触发。
我试图把它放在与LTWCoreConfig
相同的级别MVCConfig
,它被 LTW 拾取。
但CoreConfig
应该是应用程序级别,而不是 dispatchservlet 级别。由于许多 Spring Web MVC 应用程序为 DispatcherServlet 使用根上下文和子上下文。
所以我的问题是,如果我放入CoreConfig
应用程序级别,如何让 LTW 拿起它?谢谢。