Spring无法自动连线对象?是否可以在抽象类中自动装配对象。假设所有模式都在application-context.xml中提供
问题:@Service @Component应该在基类和扩展类(如果有)上使用什么批注?
例
abstract class SuperMan { @Autowire private DatabaseService databaseService; abstract void Fly(); protected void doSuperPowerAction(Thing thing) { //busy code databaseService.save(thing); } }
Extending class
public class SuperGirl extends SuperMan { @Override public void Fly() { //busy code } public doSomethingSuperGirlDoes() { //busy code doSuperPowerAction(thing) }
application-context.xml
<context:component-scan base-package="com.baseLocation" /> <context:annotation-config/>
具有自动接线字段的抽象类
public abstract class AbstractJobRoute extends RouteBuilder { @Autowired private GlobalSettingsService settingsService;
以及几个带有@Component注释定义的子级。