简体   繁体   English

Spring JMS junit测试找不到@Component注释的接收者

[英]Spring JMS junit test can't find @Component annotated receiver

I'm trying to test JMSSender and JMSReceiver, the JMSSender is autowiring correctly, but the JMSReceiver is not. 我正在尝试测试JMSSender和JMSReceiver,JMSSender正确地自动装配,但是JMSReceiver没有。

No qualifying bean of type 'br.com.framework.TestJMSReceiverImpl' available: expected at least 1 bean which qualifies as autowire candidate. 没有可用的'br.com.framework.TestJMSReceiverImpl'类型的合格Bean:期望至少有1个合格为自动装配候选的Bean。

The test class: 测试班:

@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();
    }
}

main Application class i have: 我主要的应用程序类别有:

@Configuration
@ComponentScan("br.com.framework")
@EnableAutoConfiguration(exclude = { BatchAutoConfiguration.class, DataSourceAutoConfiguration.class })
@SpringBootApplication
public class Application extends SpringBootServletInitializer {

The TestJMSReceiverImpl: TestJMSReceiverImpl:

@Component
public class TestJMSReceiverImpl extends JMSReceiver {

    public TestJMSReceiverImpl() {
        super("helloworld.q");
    }
    ...
}

The JMSReceiver: JMSReceiver:

public abstract class JMSReceiver {

    @Autowired
    JmsTemplate jmsTemplate;

    private String queue;

    public JMSReceiver(String queue) {
        this.queue = queue;
    }
    ...
}

Anyone knows what I am missing here? 有人知道我在这里想念的吗?

The TestJMSReceiverImpl class is not included in your test context. TestJMSReceiverImpl类不包含在您的测试上下文中。 You need to add it the context configuration for the SpringJmsApplicationTest class: change 您需要为它添加SpringJmsApplicationTest类的上下文配置:change

@ContextConfiguration(classes = { JMSSenderConfig.class, JMSReceiverConfig.class })

into 进入

@ContextConfiguration(classes = { JMSSenderConfig.class,
JMSReceiverConfig.class, TestJMSReceiverImpl.class })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM