spring boot 2.0 去掉自动注入druid数据源

2019-03-04  文晶 

mockserver一直使用spring boot自带的默认数据库配置方式,今天改造成单位统一的数据库组件启动报如下错误:

Description:
Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and no embedded datasource could be auto-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).


原因:spring boot自动配置数据库信息,在启动类上排除掉自动配置类即可,如下:

@SpringBootApplication(exclude= {DruidDataSourceAutoConfigure.class,DataSourceAutoConfiguration.class,
        DataSourceTransactionManagerAutoConfiguration.class,
        HibernateJpaAutoConfiguration.class})

1167°/11673 人阅读/0 条评论 发表评论

登录 后发表评论