Однако с версией 3.2.4 я получаю следующее ошибка при включении DataSourceAutoConfiguration, хотя я зарегистрировал два источника данных Oracle, которые я вижу в журналах до следующей ошибки:
Код: Выделить всё
***************************
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
Код: Выделить всё
WARN o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext:632 - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pathMappedEndpoints' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointAutoConfiguration.class]: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints]: Factory method 'pathMappedEndpoints' threw exception with message: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Unsatisfied dependency expressed through method 'healthEndpoint' parameter 0: Error creating bean with name 'healthContributorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Unsatisfied dependency expressed through method 'healthContributorRegistry' parameter 2: Error creating bean with name 'dbHealthContributor' defined in class path resource [org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthContributorAutoConfiguration.class]: Unsatisfied dependency expressed through method 'dbHealthContributor' parameter 0: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception with message: Failed to determine a suitable driver class
Код: Выделить всё
@Bean
static BeanDefinitionRegistryPostProcessor beanPostProcessor(final ConfigurableEnvironment environment) {
return new BeanDefinitionRegistryPostProcessor() {
public void postProcessBeanFactory(ConfigurableListableBeanFactory arg0) throws BeansException {
// TODO Auto-generated method stub
}
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanRegistry) throws BeansException {
createDynamicBeans(environment,beanRegistry);
}
};
}
Код: Выделить всё
spring.datasource.datasource_1.url=jdbc:
spring.datasource.datasource_1.username=
spring.datasource.datasource_1.password=
spring.datasource.datasource_1.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.datasource_1.test-on-borrow=true
spring.datasource.datasource_1.validation-query=SELECT 1 from dual
spring.datasource.datasource_1.validation-interval=0
spring.datasource.datasource_2.url=jdbc:
spring.datasource.datasource_2.username=
spring.datasource.datasource_2.password=
spring.datasource.datasource_2.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.datasource_2.test-on-borrow=true
spring.datasource.datasource_2.validation-query=SELECT 1 from dual
spring.datasource.datasource_2.validation-interval=0
Код: Выделить всё
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'io.springfox:springfox-swagger2:2.10.5'
implementation 'io.springfox:springfox-swagger-ui:2.4.0'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.4.0'
implementation 'javax.annotation:javax.annotation-api:1.3.2'
implementation 'com.oracle.database.jdbc:ojdbc10:19.22.0.0'
implementation 'com.oracle.database.security:oraclepki:23.3.0.23.09'
implementation 'com.oracle.database.security:osdt_core:21.13.0.0'
implementation 'com.oracle.database.security:osdt_cert:21.13.0.0'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
Код: Выделить всё
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
p>
Это проблема перевода Springboot с 1.x на 3.x? Или есть другой способ создать динамические компоненты источника данных, чтобы DataSourceConfiguration распознавал их и не искал конфигурацию Spring.datasource.* по умолчанию, которая ранее не использовалась в нашей версии 1.X?
Спасибо за помощь!
Добавление Spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration устраняет проблему во время выполнения, и код может подключаться к Oracle БД, но компонент DataSourceHealthIndicator не создан.
Подробнее здесь: https://stackoverflow.com/questions/784 ... dynamic-or