【发布时间】:2017-09-15 15:56:31
【问题描述】:
原因:java.lang.IllegalArgumentException:属性“driverClassName”不能为空
当我删除 @Profile 时它可以工作
@Profile("web")
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.demo.bank")
public class AppConfig extends WebMvcConfigurerAdapter {
}
作为参考,我添加了测试用例 sn-p。
@WebAppConfiguration @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = { AppConfig.class }) public class InsertTestCase { @Mock CommonService commonService; @InjectMocks HomeController homeController; @Autowired WebApplicationContext wac; MockMvc mockMvc; @Before public void init() { MockitoAnnotations.initMocks(this); } @Test public void testRoot() { try { this.mockMvc = MockMvcBuilders.standaloneSetup(homeController).build(); MvcResult mvcResult = this.mockMvc.perform(get("/")).andExpect(status().isOk()).andReturn(); logger.info("Response:-\t" + mvcResult.getResponse().getContentAsString()); } catch (Exception e) { e.printStackTrace(); } } }
【问题讨论】:
-
你能说得更具体点吗?这里到底有什么问题?
-
当我从浏览器测试时它工作正常,但从测试用例它却失败了
标签: java spring hibernate spring-mvc