抽象类,接口和自动装配 [英] Abstract classes, interfaces and Autowired

查看:336
本文介绍了抽象类,接口和自动装配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的主类:

public class Startup implements UncaughtExceptionHandler {

@Autowired
private MessageListener messageListener;

private static Startup startup;

public static void main(String[] args) {
        Startup start = new Startup();
        start.init(args); 
}

public void init(String[] args) {

    context = new ClassPathXmlApplicationContext("applicationContext.xml");
    startup = (Startup) context.getBean( "startup" );
    startup.start(); //here the messageListener is used
}

//这里去调用在使用的MessageListener方法的主类
    }

// here goes the main class that calls the method where messageListener is used }

@Component
public class ProdMessageListener 
    extends AbstractMessageListener implements MessageListener {...}

public abstract class AbstractMessageListener 
    implements MessageListener {...}

以及

@Component
public interface MessageListener extends QueueAware {...}

@Component
public interface QueueAware {...}

我的Spring上下文用来查找所有的类和接口。
然而,豆无法识别和获取:

My Spring context uses to locate all the classes and interfaces. However the bean is not recognized and I get:

类型的没有合格豆
  [com.ware.messaging.listener.MessageListener]发现
  依赖。

No qualifying bean of type [com.ware.messaging.listener.MessageListener] found for dependency.

任何想法,为什么自动装配不起作用?

Any ideas why autowiring does not work?

推荐答案

你知道问题是什么呢?春天似乎并不自动装配静态字段。现在一切正常。

Do you know what the problem was? Spring does not seem to autowire static fields. Now everything works.

这篇关于抽象类,接口和自动装配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆