当我在生产环境中以Windows服务的形式运行Sping Boot 服务时,出现以下错误。服务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()
}
2条答案
按热度按时间vxqlmq5t1#
您的mindBodyClientServiceImpl正在使用(间接)的类是org.springframework.boot.configurationprocessor.json.JSONException。
这是你的体型造成的
由于您已在此处声明为compileOnly:
但显然JSONException是在运行时使用的,所以在打包Jar2exe时会导致应用失败。解决方案可能是包含整个依赖项,如下所示:
这只是一个盲目的猜测,但您的应用程序可能会再次失败,但这一次至少您可以看到JSONException并修复底层问题。
bnl4lu3b2#
从SpringBoot 2.4开始,依赖项
不再包含在生成的fat-jar中(Sping Boot 2.4发行说明)。
Jar优化
当生成可运行的Sping Boot jar时,空的启动器依赖项现在将被自动删除。由于大多数启动器只提供可传递的依赖项,因此将它们打包到最终的jar中没有什么意义。
Sping Boot 注解处理器也被删除了,因为它们只在构建过程中有用。它们是spring-boot-autoconfigure-processor和spring-boot-configuration-processor。
如果异常是在您自己的代码中引发的,请检查您没有使用
如果您正在使用它们,请更换它们,例如:
您可能需要包含相关的dependency: