【发布时间】:2018-05-22 02:10:38
【问题描述】:
我正在尝试测试 JMSSender 和 JMSReceiver,JMSSender 自动装配正确,但 JMSReceiver 没有。
没有符合条件的 bean 类型 'br.com.framework.TestJMSReceiverImpl' 可用: 预计至少有 1 个 bean 符合自动装配候选资格。
测试类:
@RunWith(SpringRunner.class)
@DirtiesContext
@ContextConfiguration(classes = { JMSSenderConfig.class, JMSReceiverConfig.class })
@TestPropertySource(properties = { "spring.activemq.broker-url = vm://localhost:61616" })
public class SpringJmsApplicationTest {
@ClassRule
public static EmbeddedActiveMQBroker broker = new EmbeddedActiveMQBroker();
@Autowired
private JMSSender sender;
@Autowired
private TestJMSReceiverImpl receiver;
@Test
public void testReceive() throws Exception {
sender.send("helloworld.q", "Daleee");
receiver.receive();
}
}
我拥有的主要应用程序类:
@Configuration
@ComponentScan("br.com.framework")
@EnableAutoConfiguration(exclude = { BatchAutoConfiguration.class, DataSourceAutoConfiguration.class })
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
TestJMSReceiverImpl:
@Component
public class TestJMSReceiverImpl extends JMSReceiver {
public TestJMSReceiverImpl() {
super("helloworld.q");
}
...
}
JMSReceiver:
public abstract class JMSReceiver {
@Autowired
JmsTemplate jmsTemplate;
private String queue;
public JMSReceiver(String queue) {
this.queue = queue;
}
...
}
有人知道我在这里缺少什么吗?
【问题讨论】:
-
扫描时是否包含
TestJMSReceiverImpl? (它在正确的包装中吗?) -
它在 br.com.framework 包上,我猜它是正确的..
标签: java spring junit jms autowired