zoukankan      html  css  js  c++  java
  • springboot禁用数据库自动装配

    笔者最近在做测试用例(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, 冰冻鱼. 请尊重作者劳动成果,复制转载保留本站链接! 应用开发笔记

  • 相关阅读:
    随机过程之第一次出现的期望
    js模板引擎介绍搜集
    qt的安装和debug
    $parse/$eval和$observe/$watch如何区分
    angular controller as syntax vs scope
    Angularjs Controller 间通信机制
    Ng-template寄宿方式
    angularjs移除不必要的$watch
    angularJs项目实战!02:前端的页面分解与组装
    推荐几个可以与PhoneGap很好搭配的UI框架
  • 原文地址:https://www.cnblogs.com/passedbylove/p/12398048.html
Copyright © 2011-2022 走看看