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);
}
}
扩展类
public class SuperGirl extends SuperMan {
@Override
public void Fly() {
//busy code
}
public doSomethingSuperGirlDoes() {
//busy code
doSuperPowerAction(thing)
}
应用程序上下文.xml
<context:component-scan base-package="com.baseLocation" />
<context:annotation-config/>