由以下原因引起:java.lang.ClassNotFoundException: org.springframewor



当我在本地运行应用程序时,应用程序已经启动并运行,但当我在Kubernetes集群中部署相同的应用程序时,我得到错误

误差

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)

我在应用程序中使用的依赖项是

  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.RELEASEspring-cloud-starter-netflix-ribbon - 2.0.0.RELEASE
  11. spring-boot-starter-actuator
  12. commons-lang3 - 3.8.1
  13. lombok
  14. spring-cloud-starter-config - 2.0.3.RELEASE
  15. micro -registry-prometheus - 1.2.2
  16. 微米芯- 1.2.2
  17. spring-boot-starter-test
  18. spring-cloud-dependencies - FinchleySR3

您使用的Spring Cloud Kubernetes版本(1.1.10.RELEASE)需要Spring Boot 2.2.x。您使用的是2.0.x。这个旧版本的Spring Boot使用的是不包含org.springframework.core.env.Profiles类的旧版本Spring Framework。它是在Spring Framework 5.1和Spring Boot 2.0中引入的。使用Spring Framework 5.0.x。

你应该更新你的依赖版本以确保它们是兼容的。为了更容易做到这一点,我建议使用spring-cloud-dependenciesbom,如其项目页面所示。

相关内容