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 />
.