我有以下主要课程:
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 {...}
and
public abstract class AbstractMessageListener
implements MessageListener {...}
也
@Component
public interface MessageListener extends QueueAware {...}
@Component
public interface QueueAware {...}
我的 Spring 上下文用于定位所有类和接口。
然而,该豆未被识别,我得到:
没有合格的 bean 类型
找到了 [com.ware.messaging.listener.MessageListener]
依赖性。
有什么想法为什么自动装配不起作用?
只需确保您已将基础包添加到 spring 上下文配置中,如下所示,以允许 spring 将所有组件加载到容器中
<context:component-scan base-package="pakage1.package2"/>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)