简体   繁体   English

NoSuchMethodException:springframework.boot.autoconfigure.http.HttpMessageConverters

[英]NoSuchMethodException: springframework.boot.autoconfigure.http.HttpMessageConverters

I want to use Java 9 with Spring. But I get exception:我想将 Java 9 与 Spring 一起使用。但出现异常:

Caused by: org.springframework.aop.framework.AopConfigException: Unable to instantiate proxy using Objenesis, and regular proxy instantiation via default constructor fails as well; nested exception is java.lang.NoSuchMethodException: org.springframework.boot.autoconfigure.http.HttpMessageConverters$$EnhancerBySpringCGLIB$$1d90bff9.<init>()
    at deployment.datalis_gateway.war//org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:82)
    at deployment.datalis_gateway.war//org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:205)
    ... 62 more
Caused by: java.lang.NoSuchMethodException: org.springframework.boot.autoconfigure.http.HttpMessageConverters$$EnhancerBySpringCGLIB$$1d90bff9.<init>()
    at java.base/java.lang.Class.getConstructor0(Class.java:3302)
    at java.base/java.lang.Class.getDeclaredConstructor(Class.java:2512)
    at deployment.datalis_gateway.war//org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:76)
    ... 63 more

Do you know how I can configure Java 9 to find this restricted Java package?你知道我如何配置 Java 9 来找到这个受限制的 Java package 吗?

I came across the same error when trying to deploy a Spring Boot 2 application to Wildfly 13. This is the only Stack Overflow question that came up when I was searching for answers, so I thought I'd leave my findings here in case anyone else has the same issue, because my solution was very different from the only other answer here right now.我在尝试将 Spring Boot 2 应用程序部署到 Wildfly 13 时遇到了同样的错误。这是我在寻找答案时出现的唯一 Stack Overflow 问题,所以我想我会把我的发现留在这里以防其他人有同样的问题,因为我的解决方案与现在这里唯一的其他答案非常不同。

My application would run just fine using the embedded Tomcat server, but deploying to Wildfly would fail with the same AopConfigException asked about in this question.我的应用程序可以使用嵌入式 Tomcat 服务器运行得很好,但是部署到 Wildfly 会失败,并出现在这个问题中询问的相同 AopConfigException。 I also noticed in the root cause of the exception that Spring was looking for a no-arg constructor, and when I added no-arg constructors in all my autowired Spring components, the service actually deployed to Wildfly and ran with no problems.我还在异常的根本原因中注意到 Spring 正在寻找一个无参数构造函数,当我在所有自动装配的 Spring 组件中添加无参数构造函数时,该服务实际上部署到 Wildfly 并且没有问题地运行。 But this seemed like a hacky workaround that felt wrong, so I looked for a better solution.但这似乎是一种感觉不对的hacky解决方法,因此我寻找了更好的解决方案。

I learned from this github issue that this exception happens in Wildfly because Jboss Modules are not exposing some dependencies needed by Objenesis to do constructor injection.我从这个 github issue中了解到,这个异常发生在 Wildfly 中是因为 Jboss Modules 没有暴露 Objenesis 进行构造函数注入所需的一些依赖项。 The suggested solution they give is to add the dependencies by simply updating the project build as follows:他们给出的建议解决方案是通过简单地更新项目构建来添加依赖项,如下所示:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <archive>
            <manifestEntries>
                <Dependencies>jdk.unsupported</Dependencies>
            </manifestEntries>
        </archive>
    </configuration>
</plugin>

If this works for you, congratulations.如果这对你有用,那么恭喜你。 I pieced together from this JBoss issue that the above solution is simply a way of adding "jdk.unsupported" as a "Dependency" in the MANIFEST.MF file.我从这个 JBoss 问题拼凑起来,上面的解决方案只是在 MANIFEST.MF 文件中添加“jdk.unsupported”作为“依赖项”的一种方式。 Unfortunately for me, this is part of a Maven pom, and my team uses Gradle for build management, so I had to find another solution.对我来说不幸的是,这是 Maven pom 的一部分,我的团队使用 Gradle 进行构建管理,所以我不得不寻找另一个解决方案。

Solution that works in Gradle OR Maven适用于 Gradle 或 Maven 的解决方案

Although there is probably a Gradle specific way to accomplish the above, I found from this JBoss development guide that you can add a dependency into the MANIFEST.MF using the jboss-deployment-structure.xml with the following contents:尽管可能有 Gradle 特定的方法来完成上述操作,但我从这个 JBoss 开发指南中发现,您可以使用 jboss-deployment-structure.xml 将依赖项添加到 MANIFEST.MF 中,内容如下:

<jboss-deployment-structure>
    <deployment>
        <dependencies>
            <module name="jdk.unsupported"/>
        </dependencies>
    </deployment>
</jboss-deployment-structure>

This seems like the preferred solution even if you do use Maven because it will work the same if you switch to Gradle down the road.即使您确实使用了 Maven,这似乎也是首选解决方案,因为如果您以后切换到 Gradle,它的工作方式也是一样的。 Of course, this solution only works if the issue is isolated to JBoss/Wildfly.当然,此解决方案仅在问题与 JBoss/Wildfly 相关的情况下才有效。

*Note (in case the link to the JBoss guide goes down): jboss-deployment-structure.xml file goes in the WEB-INF or META-INF directory for a war/jar application respectively. *注意(以防 JBoss 指南的链接失效):jboss-deployment-structure.xml 文件分别位于 war/jar 应用程序的 WEB-INF 或 META-INF 目录中。

Also worth noting, I am seeing this issue on Java 11 and Wildfly 13, but I very strongly suspect that the same issue exists on Java 9 and 10 and on other versions of JBoss/Wildfly as well.同样值得注意的是,我在 Java 11 和 Wildfly 13 上看到了这个问题,但我非常怀疑 Java 9 和 10 以及其他版本的 JBoss/Wildfly 上也存在同样的问题。

In my case VM argument --add-modules=jdk.unsupported helped.在我的情况下,VM 参数--add-modules=jdk.unsupported帮助。 In this case ObjenesisCglibAopProxy creates a proxy using sun.reflect.ReflectionFactory and doesn't look for the absent constructor.在这种情况下ObjenesisCglibAopProxy使用创建一个代理sun.reflect.ReflectionFactory ,不看的缺席构造函数。

if you add jdk.unsupported as global module, you need not change the applications:如果将 jdk.unsupported 添加为全局模块,则无需更改应用程序:

<global-modules>
      <module name="jdk.unsupported"/>

You need to use a couple of --add-opens to your runtime JVM arguments and be prepared to add opens ... just about everywhere in your application that exposes something to the Spring context that isn't exported yet.您需要对您的运行时 JVM 参数使用几个--add-opens并准备添加opens ...几乎在您的应用程序中的任何地方都会向尚未导出的 Spring 上下文公开某些内容。 More information 更多信息

The issue seem to be with the java compiler version.问题似乎与 java 编译器版本有关。 I got this error when the compiled code was java version 11 and if I change the compiler to 8 I didn't see th当编译代码为 java 版本 11 时出现此错误,如果我将编译器更改为 8 我没有看到

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.NoClassDefFoundError:org / springframework / boot / autoconfigure / security / SecurityPrerequisite - java.lang.NoClassDefFoundError: org/springframework/boot/autoconfigure/security/SecurityPrerequisite Spring,org.springframework.boot.autoconfigure的Gradle编译错误 - Spring, Gradle compiling error with org.springframework.boot.autoconfigure 找不到 class [org.springframework.boot.autoconfigure.condition.OnBeanCondition] - Could not find class [org.springframework.boot.autoconfigure.condition.OnBeanCondition] 无法解析导入org.springframework.boot.autoconfigure.web.ErrorAttributes - The import org.springframework.boot.autoconfigure.web.ErrorAttributes cannot be resolved org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker 循环引用 Spring Boot 2.1.3 - org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker circular reference Spring Boot 2.1.3 无法解析 org.springframework.boot:spring-boot-autoconfigure:2.6.1 springboot | 达博 - Cannot resolve org.springframework.boot:spring-boot-autoconfigure:2.6.1 springboot | dubbo Spring 启动 java.lang.IllegalArgumentException:找不到 class [org.springframework.boot.autoconfigure.security.securityAutoConfiguration] - Spring boot java.lang.IllegalArgumentException : could not find class [org.springframework.boot.autoconfigure.security.securityAutoConfiguration] Spring Boot 2 中的 HttpMessageConverters 发生了什么? - What happend to HttpMessageConverters in spring boot 2? 在Spring Boot中使用JSON HttpMessageConverters - Using JSON HttpMessageConverters with Spring Boot spring boot 数据库错误数据源“org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration” - spring boot database error datasource "org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM