As I know, field injection
is not recommended. Should use constructor
instead.
What I\'m trying to do here is using @Autowired
in
I'd suggest using @Configuration
classes. That way you can remove Spring annotations entirely from your business classes:
public class Sub extends Base {
private final MySubService mySubService;
public Sub(MySubService mySubService, MyDemoService myDemoService){
super(myDemoService);
this.mySubService = mySubService;
}
}
Spring config:
@Configuration
public class SubConfig{
@Bean
public Sub sub(MySubService subService, MyDemoService demoService){
return new Sub(subService, demoService);
}
}
With Configuration classes, you no longer rely on magical classpath scanning, but actually instantiate beans manually again. There's a lot less surprises in this approach.