2013-04-11 35 views
2

我有以下的主类:抽象类,接口和自动装配Autowired

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使用 }

@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上下文用来定位所有的类和接口。 然而豆无法识别和获取:

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

任何想法,为什么自动连接不起作用?

+0

自动线在哪里? – Kent 2013-04-11 14:25:48

+0

编译错误:MessageListener正在扩展一个接口 – MStodd 2013-04-11 14:29:30

+0

嗯,不是。接口可以扩展接口。看到[链接](http://stackoverflow.com/questions/616684/java-interface-extends-questions) – luksmir 2013-04-11 14:58:17

回答

0

你知道问题是什么? Spring似乎不自动调用静态字段。现在一切正常。

2

只要确保您已将基础包到像下面的Spring上下文配置,以允许弹簧所有组件装入容器

<context:component-scan base-package="pakage1.package2"/> 
+0

我做到了没有效果。 – luksmir 2013-04-11 14:43:12

+0

实现类假设为组件而不是接口 – Lavanya 2013-04-11 14:48:11

+0

实现类是一个组件ProdMessageListener。这是正确的/不正确的? – luksmir 2013-04-11 14:54:14