相关疑难解决方法(0)

Spring可以在抽象类中自动装配吗?

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);

    }
}
Run Code Online (Sandbox Code Playgroud)

扩展课程

public class SuperGirl extends SuperMan {

    @Override
    public void Fly() {
        //busy code
    }

    public doSomethingSuperGirlDoes() {

        //busy code

        doSuperPowerAction(thing)

    }
Run Code Online (Sandbox Code Playgroud)

应用程序的context.xml

<context:component-scan base-package="com.baseLocation" />
<context:annotation-config/>
Run Code Online (Sandbox Code Playgroud)

spring abstract-class autowired

57
推荐指数
3
解决办法
8万
查看次数

标签 统计

abstract-class ×1

autowired ×1

spring ×1