gpt4 book ai didi

java - 如何修复 java.lang.ClassNotFoundException : org. springframework.boot.configurationprocessor.json.JSONException 错误?

转载 作者:行者123 更新时间:2023-12-05 09:27:01 25 4
gpt4 key购买 nike

当我在生产环境中将 spring boot 服务作为 Windows 服务运行时,出现以下错误。服务 exe 由 Jar2exe 创建.

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 org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mindbodyApplication': Unsatisfied dependency expressed through field 'mindBodyClientService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mindBodyClientServiceImpl': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [com.rossmoor.mindbody.services.web.MindBodyClientServiceImpl] from ClassLoader [org.springframework.boot.loader.LaunchedURLClassLoader@18769467]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:659)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295)
at com.rossmoor.mindbody.MindbodyApplication.main(MindbodyApplication.java:43)
... 8 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mindBodyClientServiceImpl': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [com.rossmoor.mindbody.services.web.MindBodyClientServiceImpl] from ClassLoader [org.springframework.boot.loader.LaunchedURLClassLoader@18769467]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:289)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1302)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1219)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1391)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1311)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:656)
... 28 more
Caused by: java.lang.IllegalStateException: Failed to introspect Class [com.rossmoor.mindbody.services.web.MindBodyClientServiceImpl] from ClassLoader [org.springframework.boot.loader.LaunchedURLClassLoader@18769467]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:485)
at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:267)
... 40 more
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/configurationprocessor/json/JSONException
at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3402)
at java.base/java.lang.Class.getDeclaredMethods(Class.java:2504)
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:467)
... 42 more
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.configurationprocessor.json.JSONException
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:587)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 46 more

奇怪的是,当我在生产机器上通过 Intellij Idea 运行它时,它运行正常。Intellij Idea 中的服务 exe 和代码都可以在我的开发机器上正常工作。这是我的 build.gradle 文件:

plugins {
id 'org.springframework.boot' version '2.7.1'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

configurations {
compileOnly {
extendsFrom annotationProcessor
}
}

repositories {
mavenCentral()
}

dependencies {
// implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
// developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.microsoft.sqlserver:mssql-jdbc'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'

// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'

// // https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp
// implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.10.0'

// https://mvnrepository.com/artifact/org.hibernate/hibernate-core
implementation group: 'org.hibernate', name: 'hibernate-core', version: '5.6.9.Final'

// https://mvnrepository.com/artifact/antlr/antlr
implementation group: 'antlr', name: 'antlr', version: '2.7.7'

// https://mvnrepository.com/artifact/com.fasterxml/classmate
implementation group: 'com.fasterxml', name: 'classmate', version: '1.5.1'

// https://mvnrepository.com/artifact/javax.activation/javax.activation-api
implementation group: 'javax.activation', name: 'javax.activation-api', version: '1.2.0'

// https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api
implementation group: 'javax.persistence', name: 'javax.persistence-api', version: '2.2'

// https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api
implementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'

// https://mvnrepository.com/artifact/net.bytebuddy/byte-buddy
implementation group: 'net.bytebuddy', name: 'byte-buddy', version: '1.12.12'

// https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime
implementation group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '4.0.0'

// https://mvnrepository.com/artifact/org.hibernate.common/hibernate-commons-annotations
implementation group: 'org.hibernate.common', name: 'hibernate-commons-annotations', version: '6.0.2.Final'

// https://mvnrepository.com/artifact/org.jboss/jandex
implementation group: 'org.jboss', name: 'jandex', version: '2.4.3.Final'

// https://mvnrepository.com/artifact/org.jboss.logging/jboss-logging
implementation group: 'org.jboss.logging', name: 'jboss-logging', version: '3.5.0.Final'

// https://mvnrepository.com/artifact/org.jboss.spec.javax.transaction/jboss-transaction-api_1.2_spec
implementation group: 'org.jboss.spec.javax.transaction', name: 'jboss-transaction-api_1.2_spec', version: '1.1.1.Final'

implementation files('lib/connection-manager-2.0.0.1.jar')
implementation files('lib/Utils-2.0.0.1.jar')
implementation files('lib/TinyLog-2.0.0.1.jar')
}

tasks.named('test') {
useJUnitPlatform()
}

最佳答案

从SpringBoot 2.4开始依赖

org.springframework.boot:spring-boot-configuration-processor

不再包含在生成的 fat-jar ( Spring Boot 2.4 Release Notes ) 中。

Jar Optimizations

When generating runnable Spring Boot jars, empty starter dependencies will now be automatically removed. Since most starters only provide transitive dependencies, there is little point in packaging them in the final jar.

Spring Boot annotation processors are also removed as well as they are only useful during the build. These are spring-boot-autoconfigure-processor and spring-boot-configuration-processor.

如果在您自己的代码中抛出异常,请检查您是否没有使用

org.springframework.boot.configurationprocessor.json.JSONException
org.springframework.boot.configurationprocessor.json.JSONObject

如果您正在使用它们,请替换它们,例如:

org.json.JSONException
org.json.JSONObject

您可能需要包含相关的 dependency :

<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20220924</version>
</dependency>

关于java - 如何修复 java.lang.ClassNotFoundException : org. springframework.boot.configurationprocessor.json.JSONException 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73071773/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com