【问题标题】:Error: Property 'driverClassName' must not be empty错误:属性“driverClassName”不能为空
【发布时间】: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


【解决方案1】:

您是否在 application.properties 或 yml 文件中添加了活动配置文件。 ? 还是通过命令行传递?

如果没有通过如下:

spring.profiles.active=web

或(来自命令)

--spring.profiles.active=web

【讨论】:

  • 是的,我已经在 WebInitializer 类中添加并开始工作,但是如果删除 _@ActiveProfile 和 _@profile,测试用例会失败,我搜索了很多但没有运气...
猜你喜欢
  • 1970-01-01
  • 2012-05-28
  • 1970-01-01
  • 1970-01-01
  • 2020-11-24
  • 1970-01-01
  • 2020-10-29
  • 2017-04-10
  • 2014-01-07
相关资源
最近更新 更多