【发布时间】:2016-01-30 20:12:54
【问题描述】:
我正在为我的一个 Spring 控制器编写一个集成测试。测试包括一个配置文件 (data-access-configuration.xml),其中使用 JNDI 配置了 DataSource。当我运行此测试时,我收到错误error creating bean with name dataSource 嵌套异常NoIntialContextException。下面是我的测试类和配置文件
配置:
<jee:jndi-lookup jndi-name="jobportal_db" id="dataSource"
expected-type="javax.sql.DataSource">
</jee:jndi-lookup>
测试
@RunWith(value=SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations = { "file:WebContent/WEB-INF/dispatcher-servlet.xml",
"classpath:com/zerosolutions/configuration/service-configuration.xml",
"classpath:com/zerosolutions/configuration/security-configuration.xml",
"classpath:com/zerosolutions/configuration/data-access-configuration.xml",
"classpath:com/zerosolutions/configuration/view-configuration.xml"})
public class TestingFrontController {
@Autowired
private WebApplicationContext wac;
private MockMvc mockMvc;
@Before
public void setUp(){
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
}
@Test
public void getLoginSignupPage() throws Exception{
mockMvc.perform(get("/login"))
.andExpect(status().isOk())
.andExpect(forwardedUrl("login"));
}
}
我该如何解决?
【问题讨论】:
标签: java spring exception datasource spring-test