本文介绍了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,抽象类和注释
发布评论