最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java.lang.NoClassDefFoundError: orgspringframeworkbootSpringApplication - Stack Overflow

programmeradmin0浏览0评论

TLDR: Jar built from source is not working while ones downloaded from an internal repo which ig points to mavenCentral does, 3 jars were the issue and only one jar is having difference to the one that is working, want to know the correct way to built the jar and resolve this issue.

In our attempt to reduce dependency on mavenCentral to fetch dependencies, we are building few jars from source and pulling other from an internal repo. Now one of our application is based on spring-boot and I have built the 3.4.1 jar and pushed it to our custom repo. Now in our build.gradle we have three repos... 1st a compliant repo but doesn't have the new version of jars, then our custom repo and then internal repo which isn't complaint for some reason. We build the podman image of the application and that is being built successfully. But as soon as we run the application we get the following error -

Exception in thread "main" java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at .springframework.boot.loader.launch.Launcher.launch(Launcher.java:102)
    at .springframework.boot.loader.launch.Launcher.launch(Launcher.java:64)
    at .springframework.boot.loader.launch.JarLauncher.main(JarLauncher.java:40)
Caused by: java.lang.NoClassDefFoundError: /springframework/boot/SpringApplication
    at com.wsa.WebSocketAgentApplication.main(WebSocketAgentApplication.java:15)
    ... 7 more
Caused by: java.lang.ClassNotFoundException: .springframework.boot.SpringApplication
    at java.base/java.URLClassLoader.findClass(URLClassLoader.java:445)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:592)
    at .springframework.boot.loader.protocol.jar.JarUrlClassLoader.loadClass(JarUrlClassLoader.java:107)
    at .springframework.boot.loader.launch.LaunchedClassLoader.loadClass(LaunchedClassLoader.java:91)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
    ... 8 more

The thing to note here is that this is coming when few spring boot jar are being fetched from repo where I built them from source. So I checked the scan report and tried excluding spring boot modules one by one and after excluding spring-boot, spring-boot-autoconfigure and spring-boot-actuator and checking logs the application is starting as usual and working fine. All three jars are being fetched from the 3rd repo and I not sure from where does the repo gets the jars from, I believe it's similar to mavenCentral but idk.

So, I have compared all three jars which I built and 3rd repo one, spring-boot and spring-boot-autoconfigure are same and no changes but for spring-boot-actuator I saw some difference in spring-configuation-metadata.json file as -

BFS
{
      "name": "management.endpoint.prometheus",
      "type": ".springframework.boot.actuate.metrics.export.prometheus.PrometheusScrapeEndpoint",
      "sourceType": ".springframework.boot.actuate.metrics.export.prometheus.PrometheusScrapeEndpoint"
    },

3rd repo
{
      "name": "management.endpoint.prometheus",
      "type": ".springframework.boot.actuate.metrics.export.prometheus.PrometheusSimpleclientScrapeEndpoint",
      "sourceType": ".springframework.boot.actuate.metrics.export.prometheus.PrometheusSimpleclientScrapeEndpoint"
    },

Now why I checked for spring-boot-autoconfigure, coz I got this error after excluding spring-boot -

Caused by: java.lang.NoClassDefFoundError: /springframework/boot/autoconfigure/condition/SpringBootCondition

and for spring-boot-actuator, I got this error after excluding the other two -

Caused by: java.lang.ClassNotFoundException: .springframework.boot.actuate.audit.AuditEventsEndpoint

So basically I want to know the correct way to built the jars as the same is working is one of our other microservices perfectly. I am not sure why this error is coming as jar from 3rd repo is working fine...

Used this command to built the jar -

gradle :spring-boot-project:spring-boot:build -x test -x :buildSrc:test -x checkstyleMain -x checkstyleTest
发布评论

评论列表(0)

  1. 暂无评论