笔者最近在做测试用例(testCase),但是实际这个测试用例根本需要数据库。启动报错:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2020-03-02 21:06:15.808 ERROR 11980 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. Reason: Failed to determine a suitable driver class Action: Consider the following: If you want an embedded database (H2, HSQL or Derby), please put it on the classpath. If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active). Process finished with exit code 1
在网上搜索了一下,找到方法,答案如下:在springboot启动类排除几个类DataSourceAutoConfiguration,DataSourceTransactionManagerAutoConfiguration,HibernateJpaAutoConfiguration
如下
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.EnableCaching; import org.springframework.scheduling.annotation.EnableAsync; @EnableAsync @EnableCaching @CacheConfig @SpringBootApplication(scanBasePackages = "com.springboot",exclude = { DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class}) public class App { public static void main( String[] args ) { SpringApplication.run(App.class, args); } }
转载自:https://blog.csdn.net/wyw815514636/article/details/80846545
© 2017, 冰冻鱼. 请尊重作者劳动成果,复制转载保留本站链接! 应用开发笔记
本博客文章绝大多数为原创,少量为转载,代码经过测试验证,如果有疑问直接留言或者私信我。
创作文章不容易,转载文章必须注明文章出处;如果这篇文章对您有帮助,点击右侧打赏,支持一下吧。
创作文章不容易,转载文章必须注明文章出处;如果这篇文章对您有帮助,点击右侧打赏,支持一下吧。