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

  • 相关阅读:
    基于wax的lua IOS插件开发
    acm
    微策略面试题:在旋转后的数组中查找元素(二分查找)
    BP神经网络
    神经网络理论基础
    机器人关节数学模型
    如何下载中文和英文的全文专利
    Java 12 骚操作, switch居然还能这样玩!
    Java 12 骚操作, String居然还能这样玩!
    Spring Boot YML 掀翻 Properties!!
  • 原文地址:https://www.cnblogs.com/passedbylove/p/12398048.html
Copyright © 2011-2022 走看看