Reputation: 285
I try to use spring weblogic LTW in my project to do some aop stuff. my project is a simple webapp servlet2.5 use spring mvc 3.2.6, running on weblogic 10.0. I have following app level configuration setup in web.xml
@Configuration @EnableLoadTimeWeaving public class AppConfig { } @Configuration @EnableTransactionManagement @ComponentScan(basePackages = { "com.blabla.model" }) public class CoreConfig { }
I also have a mvc level configuration setup in my web.xml
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = { "com.blabla.controller" })
public class MVCConfig extends WebMvcConfigurerAdapter {
}
here is my simplified 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>
so what happens is, MVCConfig
and its scanned components are all woven by LTW and works great. but CoreConfig
and its scanned components (all the DAO) are not picked up by LTW.
I guess that the CoreConfig
and AppConfig
is in the same level, so when AppConfig
and CoreConfig
are loaded, the LTW is not triggered yet.
And I tried to put the CoreConfig
in the same level as MVCConfig
, it got picked up by LTW.
but CoreConfig
is supposed to be application level, not dispatchservlet level. Since many spring web MVC applications use a root context and a child for the DispatcherServlet.
so My question is if I put CoreConfig
in the app level, how to make LTW pick it up? Thanks.
Upvotes: 1
Views: 1669
Reputation: 124898
Loadtimeweaving will only work for classes that aren't already loaded by the class loader.
Now when using XML configuration the actual bean classes are loaded after the load time weaving is enabled so it works, more or less, flawlessly for all classes.
With Java Config classes are loaded as soon as the @Configuration
annotationed class is loaded. All classes that are imported are loaded into the class loader. After this load time weaving is enabled, however only for classes that are going to be loaded after this point.
Hence the fact that it is working for classes loaded by the configuration as specified for the DispatcherServlet
and hence the problem in the ContextLoaderListener
.
One thing you can try is to put a @ComponentScan
for @Configuration
classes on the AppConfig
. And let the ContextLoaderListener
only load the AppConfig
. That might defer the class loading a little until after the load time weaving is enabled.
Something that definitely will work is putting both configuration classes in XML, remove the @EnableLoadTimeWeaving
for the AppConfig
and use a <context:load-time-weaving />
.
Upvotes: 4