提问人:KripDo 提问时间:9/5/2023 更新时间:9/12/2023 访问量:82
启动jar文件spring boot kafka的问题
The problem of starting the jar file spring boot kafka
问:
我正在使用 kafka 在 Spring boot 上做一个机器人电报,我正在 Inteligi IDEA 中构建一个项目,一切都很好,但是一旦我尝试运行 jar 文件,错误就会崩溃,我在下面提供日志。
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023-09-05 11:08:53.984 ERROR 17732 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kafkaConsumerServiceImpl': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [com.bot.hello.service.impl.KafkaConsumerServiceImpl] from ClassLoader [org.springframework.boot.loader.LaunchedURLClassLoader@32a1bec0]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:289) ~[spring-beans-5.3.25.jar!/:5.3.25]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1302) ~[spring-beans-5.3.25.jar!/:5.3.25]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1219) ~[spring-beans-5.3.25.jar!/:5.3.25]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.25.jar!/:5.3.25]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.25.jar!/:5.3.25]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.25.jar!/:5.3.25]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.25.jar!/:5.3.25]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.25.jar!/:5.3.25]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.25.jar!/:5.3.25]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955) ~[spring-beans-5.3.25.jar!/:5.3.25]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.25.jar!/:5.3.25]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.25.jar!/:5.3.25]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.8.jar!/:2.7.8]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731) ~[spring-boot-2.7.8.jar!/:2.7.8]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) ~[spring-boot-2.7.8.jar!/:2.7.8]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) ~[spring-boot-2.7.8.jar!/:2.7.8]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303) ~[spring-boot-2.7.8.jar!/:2.7.8]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292) ~[spring-boot-2.7.8.jar!/:2.7.8]
at com.bot.hello.HelloBotApplication.main(HelloBotApplication.java:24) ~[classes!/:0.0.1-SNAPSHOT]
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:578) ~[na:na]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[hello-bot-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[hello-bot-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[hello-bot-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) ~[hello-bot-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
Caused by: java.lang.IllegalStateException: Failed to introspect Class [com.bot.hello.service.impl.KafkaConsumerServiceImpl] from ClassLoader [org.springframework.boot.loader.LaunchedURLClassLoader@32a1bec0]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:485) ~[spring-core-5.3.25.jar!/:5.3.25]
at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321) ~[spring-core-5.3.25.jar!/:5.3.25]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:267) ~[spring-beans-5.3.25.jar!/:5.3.25]
... 24 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/configurationprocessor/json/JSONException
at java.base/java.lang.Class.getDeclaredMethods0(Native Method) ~[na:na]
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3502) ~[na:na]
at java.base/java.lang.Class.privateGetPublicMethods(Class.java:3527) ~[na:na]
at java.base/java.lang.Class.getMethods(Class.java:2112) ~[na:na]
at org.springframework.util.ReflectionUtils.findConcreteMethodsOnInterfaces(ReflectionUtils.java:495) ~[spring-core-5.3.25.jar!/:5.3.25]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:468) ~[spring-core-5.3.25.jar!/:5.3.25]
... 26 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.configurationprocessor.json.JSONException
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588) ~[na:na]
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151) ~[hello-bot-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ~[na:na]
... 32 common frames omitted
我尝试添加各种依赖项,例如 spring aop、spring web flux,但没有任何帮助
答:
错误消息指示类 org.springframework.boot.configurationprocessor.json.JSONException 的 java.lang.ClassNotFoundException。这个特定的异常类是spring-boot-configuration-processor的一部分,它有助于为自定义属性创建元数据,以便在IDE中获得支持。
但是,除非显式使用此类,否则应用程序在运行时需要此类是不寻常的。这有几个潜在的原因和解决方案:
检查依赖项:确保您在 pom.xml 或 build.gradle 中使用正确版本的 Spring Boot 和 Kafka 依赖项。
检查 KafkaConsumerServiceImpl:主要错误似乎与 KafkaConsumerServiceImpl 有关。检查此类或其父类/接口中是否有任何对 JSONException 的直接或间接引用。
使缓存失效并重新启动 Intellij:从顶部菜单中,按照此路径勾选所有选项,然后按“使缓存失效并重新启动”
File >> Invalidate Caches...
清理和重新生成:有时,IDE 或生成工具可能会遇到缓存问题或生成输出损坏。对项目执行清理和重新生成。对于 maven,运行 对于 gradl,运行 this .
mvn clean install
gradlew clean build
Spring Boot Configuration Processor:如果您在项目中使用 spring-boot-configuration-processor 来创建元数据,请确保它是提供的依赖项或在可选范围内,因此它不会包含在 fat jar 的运行时类路径中。这是因为通常仅在编译时才需要它。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
- 影子依赖项:如果您使用插件创建胖 jar(例如 Spring Boot Maven 插件或 Gradle 的影子插件),则依赖项的捆绑或影子方式可能会出现问题。仔细检查打包配置,以确保不会无意中省略或覆盖依赖项。
- Spring Boot 版本:检查您使用的是否是正确的 Spring Boot 版本。您可以访问 Spring Boot Initializr 网站,选择所需的依赖项,它会建议兼容的 Spring Boot 版本。
- Spring AOP 和 WebFlux:添加这些依赖项可能与问题无关。除非您有明确的理由添加它们,否则您可能希望还原这些更改。
评论