Spring Boot应用程序的loadContext上存在非法状态异常?

时间:2019-03-08 19:04:22

标签: java spring-boot junit

我有以下主要课程:

@SpringBootApplication
@EntityScan(basePackageClasses = { SampleApplication.class, Jsr310JpaConverters.class})
public class SampleApplication {

    @Value("${app.timezone}")
    private String timezone;

    @PostConstruct
    void init() {
        TimeZone.setDefault(TimeZone.getTimeZone(timezone));
    }

    public static void main(String[] args) {
        SpringApplication.run(SampleApplication.class, args);
    }
}

我有以下控制器:

@RestController
@RequestMapping("/api/alive")
public class Alive {

    @GetMapping("/ping")
    public ResponseEntity<?> ping() {
       return ResponseEntity.ok().build();
    }
}

我还有以下测试课程...

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class SampleApplicationTests {

    @Autowired
    private MockMvc mockMvc;

    @Test
    public void shouldReturnDefaultMessage() throws Exception {
        this.mockMvc.perform(get("/api/alive/ping")).andDo(print()).andExpect(status().isOk())
                .andExpect(content().string(containsString("Hello World")));
    }

}

当我尝试运行测试时...出现此错误:

java.lang.IllegalStateException: Failed to load ApplicationContext

任何帮助都将不胜感激!

注意-我知道此测试的当前状态是它将失败! -我只希望它运行:)

0 个答案:

没有答案