理解非setter方法上的@Autowired注解
Understanding of @Autowired annotation over non-setter method
假设我有方法:
@Autowired
public void doSomething(MyType t){
System.out.println(t);
}
我只是想知道 @Autowired
是否意味着在 spring 配置启动期间将调用此方法并 class 初始化?
Spring 将在启动时初始化 MyType class,稍后将由 doSomething 方法使用(同时假设 MyType class 已被适当地注释为 spring组件)。
当包含 doSomething(MyType t) 方法的 class 被初始化时,MyType 将被注入——这不一定在 Spring 启动时。
假设我有方法:
@Autowired
public void doSomething(MyType t){
System.out.println(t);
}
我只是想知道 @Autowired
是否意味着在 spring 配置启动期间将调用此方法并 class 初始化?
Spring 将在启动时初始化 MyType class,稍后将由 doSomething 方法使用(同时假设 MyType class 已被适当地注释为 spring组件)。
当包含 doSomething(MyType t) 方法的 class 被初始化时,MyType 将被注入——这不一定在 Spring 启动时。