筆者最近在做測試用例(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, 冰凍魚. 請尊重作者勞動成果,復制轉載保留本站鏈接! 應用開發筆記