Java is a high-level most used programming language that is used to create multiple applications like web applications, game applications, desktop applications, mobile applications, and many other applications. So, when programmers and developers need to create applications, the first thing that comes to their mind is Java, and they instantly switch to this language and start writing code. Java has various popular frameworks to add up to programmers’ convenience. Spring boot is the framework that is frequently used by developers and programmers to build microservices. Creating applications is simpler with spring boot. When you are working with the spring booth, you may experience the exception “ERROR org.springframework.boot.SpringApplication – Application run failed org.springframework.boot.context.config.InvalidConfigDataPropertyException: Property ‘spring.profiles.active’ imported from location ‘class path resource [application-dev.yml]’ is invalid in a profile specific resource”.
This long error makes you worried, which is common. We are here to help you solve this error by providing valuable solutions. Go ahead with the post to find out how to sort this out. Check out how the error appears
How do you get the error?
When you try to upgrade your spring cloud application to the recent version of spring boot 2.5.0, you get the following error
[main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.boot.context.config.InvalidConfigDataPropertyException: Property 'spring.profiles.active' imported from location 'class path resource [application-dev.yml]' is invalid in a profile specific resource [origin: class path resource [application-dev.yml] from skyshop-mail-1.0.jar - 42:17]
at org.springframework.boot.context.config.InvalidConfigDataPropertyException.lambda$throwOrWarn$1(InvalidConfigDataPropertyException.java:125)
Have a look at the script you used
application.yml
spring:
application:
name: mail-service
profiles:
active: dev
application-dev.yml file:
logging:
file:
name: ${java.io.tmpdir}/application.log
level:
com:
backend: DEBUG
org:
springframework: DEBUG
springframework.web: DEBUG
jwt:
expiration: 86400
secret: test112322
server:
port: 8020
servlet:
context-path: /mail
spring:
application:
name: mail-service
profiles:
active: local
data:
web:
pageable:
one-indexed-parameters: true # Fix pagination starting number to start from 1
rest:
basePath: /mail
jackson:
default-property-inclusion: non_null
jmx:
enabled: false
datasource:
url: jdbc:mariadb://localhost:3306/database
driverClassName: org.mariadb.jdbc.Driver
jpa:
hibernate:
ddl-auto: update
properties:
hibernate:
dialect: org.hibernate.dialect.MariaDBDialect
show-sql: true
username: root
password: qwerty
oauth2:
resource:
jwt:
key-pair:
alias: mytestkey
store-password: mystorepass
info:
build:
version: 1.0
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
instance:
preferIpAddress: true
This is how you land up in the error warning. Check out the next section to solve the error
Solutions To Tackle the Error Message “ERROR org.springframework.boot.SpringApplication – Application run failed org.springframework.boot.context.config.InvalidConfigDataPropertyException: Property ‘spring.profiles.active’ imported from location ‘class path resource [application-dev.yml]’ is invalid in a profile specific resource”
Solution 1 – Replace the name of the application-dev.yml to application-local.yml
To get rid of this error message, you need to rename application-dev.yml to application-local.yml. You just need to replace the word ‘dev’ with ‘local’ as it can successfully remove the error.
Solution 2 – Switch the application-dev.yml name to application-dev123.yml
To remove the error, you need to switch the name of the application-dev.yml to application-dev123.yml. It is another effective solution that is worth trying.
Solution 3 – Change the spring.profiles.active
In order to resolve the error, another simple solution you can implement is to switch spring.profiles.active to dev in your application-dev.yml file.
Spring profile is known to help you separate different aspects of the settings of your application. You can also set limit accessibility to particular environments. To prohibit any @Configuration or @Component designated with @profile when loaded:
@Configuration
@Profile("production")
public class ProductionConfiguration {
// ...
}
You can try any method for property specifications, including it in the application. Have a look at the property
spring.profiles.active=dev,hsqldb
It is another way to specify with the help of the switch.
Solution 4 – Add this to the application-dev.yml
To make the error vanish, add the following in the application-dev.yml file:
spring:
application:
name: mail-service
profiles:
active: local
Conclusion
And that’s how you resolve the error warning “ERROR org.springframework.boot.SpringApplication – Application run failed org.springframework.boot.context.config.InvalidConfigDataPropertyException: Property ‘spring.profiles.active’ imported from location ‘class path resource [application-dev.yml]’ is invalid in a profile specific resource” efficiently.
I hope it helps!