Search code examples
javaspring-bootkubernetesconfigclassnotfoundexception

Caused by: java.lang.ClassNotFoundException: org.springframework.core.env.Profiles


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 error

Error

java.lang.NoClassDefFoundError: org/springframework/core/env/Profiles
        at org.springframework.cloud.kubernetes.config.PropertySourceUtils.lambda$null$3(PropertySourceUtils.java:69)
        at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:239)
        at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:167)
        at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:139)
        at org.springframework.beans.factory.config.YamlPropertiesFactoryBean.createProperties(YamlPropertiesFactoryBean.java:135)
        at org.springframework.beans.factory.config.YamlPropertiesFactoryBean.getObject(YamlPropertiesFactoryBean.java:115)
        at org.springframework.cloud.kubernetes.config.PropertySourceUtils.lambda$yamlParserGenerator$4(PropertySourceUtils.java:77)
        at java.util.function.Function.lambda$andThen$1(Function.java:88)
        at org.springframework.cloud.kubernetes.config.ConfigMapPropertySource.processAllEntries(ConfigMapPropertySource.java:149)
        at org.springframework.cloud.kubernetes.config.ConfigMapPropertySource.getData(ConfigMapPropertySource.java:100)
        at org.springframework.cloud.kubernetes.config.ConfigMapPropertySource.<init>(ConfigMapPropertySource.java:78)
        at org.springframework.cloud.kubernetes.config.ConfigMapPropertySourceLocator.getMapPropertySourceForSingleConfigMap(ConfigMapPropertySourceLocator.java:96)
        at org.springframework.cloud.kubernetes.config.ConfigMapPropertySourceLocator.lambda$locate$0(ConfigMapPropertySourceLocator.java:79)
        at java.util.ArrayList.forEach(ArrayList.java:1259)
        at org.springframework.cloud.kubernetes.config.ConfigMapPropertySourceLocator.locate(ConfigMapPropertySourceLocator.java:78)
        at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:94)
        at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:628)
        at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:364)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:305)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230)
        at com.daimler.daivb.msl.MbappsSnapLocalSearchServiceApplication.main(MbappsSnapLocalSearchServiceApplication.java:30)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.lang.ClassNotFoundException: org.springframework.core.env.Profiles
        at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:93)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:352)

Dependencies I am using in the application are

  1. spring-boot-starter-web - 2.0.8.RELEASE
  2. gson - 2.3.1
  3. json-lib - 2.3
  4. spring-cloud-starter-kubernetes-config -1.1.10.RELEASE
  5. json - 20230227
  6. xmlrpc-client - 3.1.3
  7. spring-security-oauth2-autoconfigure - 2.0.8.RELEASE
  8. spring-security-config
  9. spring-security-web
  10. spring-cloud-starter-openfeign - 2.0.0.RELEASE
  11. spring-cloud-starter-netflix-ribbon - 2.0.0.RELEASE
  12. spring-boot-starter-actuator
  13. commons-lang3 - 3.8.1
  14. lombok
  15. spring-cloud-starter-config - 2.0.3.RELEASE
  16. micrometer-registry-prometheus - 1.2.2
  17. micrometer-core - 1.2.2
  18. spring-boot-starter-test
  19. spring-cloud-dependencies - Finchley.SR3

Solution

  • 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 the org.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.