Describe the bug spring cloud version: 2021.0.3 When using spring:config:activate:on-profile: native ,the application would fail to start with this error:
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
When switch back to spring:profiles:active:native,the application would start normally.But I didn't test .properties file.
Sample This is a module in a Maven project. It's pom is like this
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
</dependencies>
and the application.yml is
server:
port: 8888
spring:
datasource:
url: jdbc:mysql://localhost/localtest
driver-class-name: com.mysql.cj.jdbc.Driver
username: user
password: pwd
cloud:
config:
server:
native:
search-locations: file:///D:/JavaProjects/smia/configserver/src/main/resources/config/licensingservice
config:
activate:
on-profile: native
As to the parent project, it's pom is:
<packaging>pom</packaging>
<modules>
<module>configserver</module>
<module>test</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>net.feng</groupId>
<artifactId>smia</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>smia</name>
<description>smia</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>2021.0.3</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
example.zip This is the project to reprodeces the problem. I simplified the project mentioned above, but it can reproduce the problem.
Comment From: ryanjbaxter
Can you provide a complete, minimal, verifiable sample that reproduces the problem? It should be available as a GitHub (or similar) project or attached to this issue as a zip file.
Comment From: Branhub
Can you provide a complete, minimal, verifiable sample that reproduces the problem? It should be available as a GitHub (or similar) project or attached to this issue as a zip file.
I uploaded a zip to reproduce the problem.
Comment From: ryanjbaxter
Did you forget to attach the zip?
Comment From: Branhub
Did you forget to attach the zip?
I attached the zip file at the bottom
Comment From: ryanjbaxter
I am not sure this project is valid...the error is coming from spring jdbc...i am not sure what that even has to do with spring config. You also have the config client and config server on the classpath, why?
Comment From: hpoettker
@Branhub I think your application is behaving as expected.
spring.config.activate.on-profile: native declares all properties in the current YAML document (which is the whole file in your case) to be applied only if the profile native is active. This is different from spring.profiles.active: native which activates the profile native.
Comment From: Branhub
@Branhub I think your application is behaving as expected.
spring.config.activate.on-profile: nativedeclares all properties in the current YAML document (which is the whole file in your case) to be applied only if the profilenativeis active. This is different fromspring.profiles.active: nativewhich activates the profilenative.
Oh,I didn't see the difference between spring.config.activate.on-profile and spring.profiles.active.Now I see it and figured out why the app fail to start.Thanks