美文网首页
如何在没有SpringBootApplication的项目中启动

如何在没有SpringBootApplication的项目中启动

作者: 十毛tenmao | 来源:发表于2021-06-01 13:35 被阅读0次

有一些子项目其中包含了整套Web后台服务,但是本身并不作为独立的进程启动(没有SpringBootApplication),而是作为jar包被其他项目引用。这样单元测试启动的时候就会遇到错误java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test

解决方法

解决方法倒是很简单,既然是缺少SpringBootApplication,那么就在单元测试代码中,增加一个有SpringBootApplication的启动类就可以了。这样既不影响子项目的定位(不独立启动),又可以完成单元测试

  • UtApplication.java
@SpringBootApplication
class UtApplication {
    static void main(String[] args) {
        SpringApplication.run(UtApplication.class, args);
    }
}

参考

相关文章

网友评论

      本文标题:如何在没有SpringBootApplication的项目中启动

      本文链接:https://www.haomeiwen.com/subject/uhmwsltx.html