Spring,抽象类和注释 [英] Spring, abstract class and annotations
本文介绍了Spring,抽象类和注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个非常简单的抽象类
I've got a pretty simple abstract class
public abstract class AbstractServiceActions {
@Autowired
protected DatabaseModel dbModel;
protected User user;
protected boolean complete;
protected String serviceResult;
public AbstractServiceActions(User user) {
this.user = user;
this.serviceResult = "";
}
public abstract String doAction();
}
现在你可以看到,我正在尝试自动装配DatabaseModel。但在我的扩展类中,我只接受dbModel的null。
Now you can see, I'm trying to autowire the DatabaseModel. But in my extended class I only recieve null for the dbModel.
@Component
public class CreateDatabaseAction extends AbstractServiceActions {
....
}
问题:我在这里尝试一些不可能的事情吗?
Question: Am I trying something impossible here?
推荐答案
您的设置似乎没问题。原因可能在于其他地方。也许您使用 new CreateDatabaseAction()
来实例化该类,而不是让spring执行此操作。
Your setup seems fine. The reason perhaps lies elsewhere. Maybe you are instantiating the class with new CreateDatabaseAction()
, rather than letting spring do this.
这篇关于Spring,抽象类和注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文