使用Exclude的EnableAutoConfiguratio

使用Exclude的EnableAutoConfiguratio

本文介绍了Spring Boot - 使用Exclude的EnableAutoConfiguration不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用最新的Spring启动版本,我正在尝试设置应用程序,但我想禁用DataSource配置。我的配置类如下所示:

  @Configuration 
@ComponentScan
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration .class})
公共类ApiApplicationConfig {}

但是当我运行应用程序时,我我得到以下stacktrace:

 引起:org.springframework.beans.factory.BeanCreationException:无法确定嵌入式数据库驱动程序类数据库类型NONE。如果您想要一个嵌入式数据库,请在类路径上放置一个受支持的数据库。 
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.getDriverClassName(DataSourceProperties.java:137)
at org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration $ NonEmbeddedConfiguration.dataSource(DataSourceAutoConfiguration.java: 116)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke( DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java: 162)
... 31更多

我错过了配置中的任何内容以完全禁用数据源配置?我将手动设置一个DataSource,所以我不希望Spring为我处理这个。

解决方案

这似乎是一个奇怪的情况,其中 DataSourceAutoConfiguration.NonEmbeddedDataSourceCondition 找到一个DataSource类加载器,但没有DataSource。我们在运行集成测试时遇到了spring-boot 1.2.2的问题。



无论如何,我们运行了 gradle依赖项找出在tomcat-jdbc中引入的内容,最后用普通的spring-jdbc替换spring-boot-jdbc依赖项。如果您的依赖项中没有tomcat-jdbc,则可以在 DataSourceAutoConfiguration.NonEmbeddedDataSourceCondition.getDataSourceClassLoader()中设置断点,以找出它找到的驱动程序。 / p>

I am using the latest spring boot version and I am trying to setup an application but I want to disable the DataSource configuration. My configuration class looks like this:

@Configuration
@ComponentScan
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class ApiApplicationConfig { }

but when I run the application, I am getting the following stacktrace:

Caused by: org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.getDriverClassName(DataSourceProperties.java:137)
at org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration.dataSource(DataSourceAutoConfiguration.java:116)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 31 more

Am I missing anything in my configuration to completely disable datasource configuration? I will be manually setting up a DataSource, so I dont want spring to handle this for me.

解决方案

This seems to be a weird situation where DataSourceAutoConfiguration.NonEmbeddedDataSourceCondition finds a DataSource class loader, but no DataSource. We had this problem with spring-boot 1.2.2 while running an integration test.

Anyway, we ran gradle dependencies to find out what was pulling in tomcat-jdbc and ended up replacing our spring-boot-jdbc dependency with plain spring-jdbc. If you don't have tomcat-jdbc in your dependencies, it may help to set a breakpoint in DataSourceAutoConfiguration.NonEmbeddedDataSourceCondition.getDataSourceClassLoader() to find out what driver it finds.

这篇关于Spring Boot - 使用Exclude的EnableAutoConfiguration不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 21:15