We have large java applications with thousands of beans that profile the slow initialization of the spring context, we found that automatic wiring by type is what takes up most of the context loading time. An autowiring bean by name seems to improve context initialization by an order of magnitude. However, I could not find a way to autowire beans by name as constructor arguments.
Below is an authorized member that works fine, spring searches by name:
class MyClass {
@Resource
private MyBean mybean;
}
But since @Resource only applies to members and methods, this does not apply to the constructor. We tried using @Inject with @Named and @Autowired with @Qualifier, but spring does a slow search by type:
class MyClass {
@Inject
public MyClass(@Named("myBean") MyBean myBean) {
}
}
class MyClass {
@Autowired
public MyClass(@Qualifer("myBean") MyBean myBean) {
}
}
spring ?
( bean), .