In this post, we will see how to resolve Caused by: java.lang.ClassNotFoundException: org.springframework.core.env.Profiles
Question:
When I run the application locally the application is up and running but when i deploy the same application in the Kubernetes cluster i am getting the errorError
- spring-boot-starter-web – 2.0.8.RELEASE
- gson – 2.3.1
- json-lib – 2.3
- spring-cloud-starter-kubernetes-config -1.1.10.RELEASE
- json – 20230227
- xmlrpc-client – 3.1.3
- spring-security-oauth2-autoconfigure – 2.0.8.RELEASE
- spring-security-config
- spring-security-web
- spring-cloud-starter-openfeign – 2.0.0.RELEASE
- spring-cloud-starter-netflix-ribbon – 2.0.0.RELEASE
- spring-boot-starter-actuator
- commons-lang3 – 3.8.1
- lombok
- spring-cloud-starter-config – 2.0.3.RELEASE
- micrometer-registry-prometheus – 1.2.2
- micrometer-core – 1.2.2
- spring-boot-starter-test
- spring-cloud-dependencies – Finchley.SR3
Best Answer:
The version of Spring Cloud Kubernetes that you are using (1.1.10.RELEASE) requires Spring Boot 2.2.x. You are using 2.0.x. This older version of Spring Boot uses an older version of Spring Framework that does not contain theorg.springframework.core.env.Profiles
class. It was introduced in Spring Framework 5.1 and Spring Boot 2.0.x uses Spring Framework 5.0.x.You should update your dependency versions to ensure that they’re compatible. To make it easier to do so, I would recommend using the
spring-cloud-dependencies
bom as shown on its project page.If you have better answer, please add a comment about this, thank you!
Source: Stackoverflow.com