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

  • 相关阅读:
    作用域随笔
    关于取数组地址的识记(&s+1,s+1,&s[0]+1)
    c中关于#与##的简易使用
    Qt Creator的配置
    sizeof对int long double char的使用
    i++与++i的区别
    for循环执行顺序
    gcc 编译的4个过程简单识记
    各进制之间转化识记
    删除临时文件
  • 原文地址:https://www.cnblogs.com/passedbylove/p/12398048.html
Copyright © 2011-2022 走看看