I am using Java-based config to set up my Spring application context like this:
@Configuration
@Lazy
@ComponentScan(basePackageClasses = {MyProject.class, OtherProject.class})
public class MyAppConfig {
...
}
Beans defined explicitly in the config are loaded lazily, like you would expect. However, scanned classes annotated with @Named are always loaded eagerly. How can I solve this?
Any help is appreciated.
Note that for classes in the MyProject package, I can work around this by annotating them with @Lazy as well. But the other project does not have a dependency to Spring and I want to keep it like that (hence @Named and not @Component).
Note also that this does not seam to be a problem in XML-based config. There, setting default-lazy-init="true" in the <beans> tag seams to do what I want (although I haven't tested that).