junit测试NoSuchBeanDefinitionException: No bean named 'dataSource' is define

junit测试这个问题坑了我两次,印象很深刻,这都是什么bean找不到的问题,其实这个问题很简单,就是spring的配置文件没有全部加载到junit测试环境。

我们要做的就是要检查一下,所有的spring的配置文件是否添加到了junit的测试环境,多个配置文件加载如下:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath*:/applicationContext_realm.xml",
                                    "classpath*:/applicationContext_daily.xml",
                                    "classpath*:/applicationContext.xml",
                                    "classpath*:/applicationContext_airwarm.xml",
                                    "classpath*:/applicationContext_airwet.xml",
                                    "classpath*:/applicationContext_illum.xml",
                                    "classpath*:/applicationContext_rainfall.xml"
                                })

public class testRealmEbo {

    }

猜你喜欢

转载自blog.csdn.net/sihai12345/article/details/80942961
今日推荐