Spring,抽象类和注释

编程入门 行业动态 更新时间:2024-10-27 10:32:32
本文介绍了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,抽象类和注释

本文发布于:2023-10-31 05:42:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545176.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:注释   抽象类   Spring

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!