gpt4 book ai didi

validation - Jersey 2.6 REST 服务升级到 Java 8 tomcat 8 异常 :java. lang.NoSuchMethodError : javax. validation.Configuration.getBootstrapConfiguration

转载 作者:行者123 更新时间:2023-12-04 02:24:40 28 4
gpt4 key购买 nike

我们有一场 war ,通过基于 hibernate-4.2.7 验证(实现 validation-api-1.0.0.GA)的验证来公开 jersey 2.6 上的休息服务。

在我们升级到 java 8 和 tc-server 3.1.X 之前一切正常。
升级到 java 8 后,验证 api 中似乎出现了问题。
我们得到

java.lang.NoSuchMethodError: javax.validation.Configuration.getBootstrapConfiguration()Ljavax/validation/BootstrapConfiguration;



当我们向客户端发送休息请求时。
最奇怪的是,这种行为不是一致的
当我从依赖项中添加或删除 jar 时,它有时会起作用,有时会不起作用。

我们得到以下异常
SEVERE [tomcat-http--1] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [jerseyServlet] in context with path [/Analyzer] threw exception [A MultiException has 1 exceptions.  They are:
1. java.lang.NoSuchMethodError: javax.validation.Configuration.getBootstrapConfiguration()Ljavax/validation/BootstrapConfiguration;
] with root cause
java.lang.NoSuchMethodError: javax.validation.Configuration.getBootstrapConfiguration()Ljavax/validation/BootstrapConfiguration;
at org.glassfish.jersey.server.validation.internal.ValidationBinder$ConfiguredValidatorProvider.getTraversableResolver(ValidationBinder.java:287)
at org.glassfish.jersey.server.validation.internal.ValidationBinder$ConfiguredValidatorProvider.getDefaultValidatorContext(ValidationBinder.java:268)
at org.glassfish.jersey.server.validation.internal.ValidationBinder$ConfiguredValidatorProvider.getDefaultValidator(ValidationBinder.java:248)
at org.glassfish.jersey.server.validation.internal.ValidationBinder$ConfiguredValidatorProvider.provide(ValidationBinder.java:199)
at org.glassfish.jersey.server.validation.internal.ValidationBinder$ConfiguredValidatorProvider.provide(ValidationBinder.java:173)
at org.jvnet.hk2.internal.FactoryCreator.create(FactoryCreator.java:96)
at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:456)
at org.jvnet.hk2.internal.PerLookupContext.findOrCreate(PerLookupContext.java:69)
at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2445)
at org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:621)
at org.jvnet.hk2.internal.IterableProviderImpl.get(IterableProviderImpl.java:107)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:135)
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$VoidOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:136)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:104)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:406)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:350)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:106)
at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:259)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:319)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:236)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1028)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:373)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:381)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:344)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:219)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at SourceResolverFilter.doFilter(SourceResolverFilter.java:71)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:277)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

查看堆栈跟踪,您可以看到 jersey 正在调用 Configuration.getBootstrapConfiguration ,它在 validation-api-1.1.0.Final 中提供,但在 validation-api-1.0.0.GA 中没有。
Our dependencies tree (excluding product specific jars) looks like

--- maven-dependency-plugin:2.10:tree (default-cli) ---
excluded war-SNAPSHOT
+- excluded jar
| +- excluded jar
| | \- org.hibernate:hibernate-validator:jar:4.2.0.Final:compile
| +- org.springframework:spring-context:jar:4.0.2.RELEASE:compile
| | +- org.springframework:spring-aop:jar:4.0.2.RELEASE:compile
| | | \- aopalliance:aopalliance:jar:1.0:compile
| | +- org.springframework:spring-beans:jar:4.0.2.RELEASE:compile
| | +- org.springframework:spring-core:jar:4.0.2.RELEASE:compile
| | \- org.springframework:spring-expression:jar:4.0.2.RELEASE:compile
| +- org.glassfish.jersey.core:jersey-server:jar:2.6:compile
| | +- org.glassfish.jersey.core:jersey-common:jar:2.6:compile
| | | +- org.glassfish.jersey.bundles.repackaged:jersey-guava:jar:2.6:compile
| | | \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.1:compile
| | +- org.glassfish.jersey.core:jersey-client:jar:2.6:compile
| | +- javax.ws.rs:javax.ws.rs-api:jar:2.0:compile
| | +- javax.annotation:javax.annotation-api:jar:1.2:compile
| | +- org.glassfish.hk2:hk2-api:jar:2.2.0:compile
| | | +- org.glassfish.hk2:hk2-utils:jar:2.2.0:compile
| | | \- org.glassfish.hk2.external:aopalliance-repackaged:jar:2.2.0:compile
| | +- org.glassfish.hk2.external:javax.inject:jar:2.2.0:compile
| | +- org.glassfish.hk2:hk2-locator:jar:2.2.0:compile
| | \- javax.validation:validation-api:jar:1.0.0.GA:compile
| +- org.glassfish.jersey.media:jersey-media-json-jackson:jar:2.6:compile
| | +- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile
| | +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
| | +- org.codehaus.jackson:jackson-jaxrs:jar:1.9.13:compile
| | \- org.codehaus.jackson:jackson-xc:jar:1.9.13:compile
| +- org.glassfish.jersey.containers:jersey-container-servlet:jar:2.6:compile
| | \- org.glassfish.jersey.containers:jersey-container-servlet-core:jar:2.6:compile
| +- org.glassfish.jersey.ext:jersey-spring3:jar:2.6:compile
| | +- org.glassfish.hk2:hk2:jar:2.2.0:compile
| | | +- org.glassfish.hk2:config-types:jar:2.2.0:compile
| | | +- org.glassfish.hk2:core:jar:2.2.0:compile
| | | +- org.glassfish.hk2:hk2-config:jar:2.2.0:compile
| | | | \- org.jvnet:tiger-types:jar:1.4:compile
| | | +- org.glassfish.hk2:hk2-runlevel:jar:2.2.0:compile
| | | \- org.glassfish.hk2:class-model:jar:2.2.0:compile
| | +- org.glassfish.hk2:spring-bridge:jar:2.2.0:compile
| | \- org.springframework:spring-web:jar:4.0.2.RELEASE:compile
| \- org.glassfish.jersey.ext:jersey-bean-validation:jar:2.6:compile
+- log4j:log4j:jar:1.2.17:compile
+- commons-logging:commons-logging:jar:1.1.1:compile
+- org.jasypt:jasypt-spring31:jar:1.9.0:compile
| \- org.jasypt:jasypt:jar:1.9.0:compile
+- excluded jar
| +- excluded jar
| | +- commons-configuration:commons-configuration:jar:1.5:compile
| | | +- commons-collections:commons-collections:jar:3.2.1:compile
| | | +- commons-lang:commons-lang:jar:2.4:compile
| | | +- commons-digester:commons-digester:jar:1.8:compile
| | | | \- commons-beanutils:commons-beanutils:jar:1.7.0:compile
| | | \- commons-beanutils:commons-beanutils-core:jar:1.7.0:compile
| | +- commons-codec:commons-codec:jar:1.6:compile
| | \- org.apache.commons:commons-lang3:jar:3.3.2:compile
| +- excluded jar
| +- excluded jar
| | \- net.sf.ehcache:ehcache-core:jar:2.4.7:compile
| +- org.hibernate:hibernate-core:jar:4.2.7.Final:compile
| | +- antlr:antlr:jar:2.7.7:compile
| | +- org.jboss.logging:jboss-logging:jar:3.1.0.GA:compile
| | +- dom4j:dom4j:jar:1.6.1:compile
| | +- org.javassist:javassist:jar:3.18.0-GA:compile
| | +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.1.Final:compile
| | +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
| | \- org.hibernate.common:hibernate-commons-annotations:jar:4.0.2.Final:compile
| +- org.springframework:spring-orm:jar:4.0.2.RELEASE:compile
| | +- org.springframework:spring-jdbc:jar:4.0.2.RELEASE:compile
| | \- org.springframework:spring-tx:jar:4.0.2.RELEASE:compile
| +- javax.servlet:servlet-api:jar:3.0:provided
| +- excluded jar
| | \- excluded jar
| +- excluded jar
| \- com.zaxxer:HikariCP-java6:jar:2.3.7:compile
| \- org.slf4j:slf4j-api:jar:1.7.6:compile
+- excluded jar-SNAPSHOT:compile
| \- excluded jar
+- excluded jar-SNAPSHOT:compile
| \- excluded jar
+- excluded jar-SNAPSHOT:compile
| \- excluded jar
| +- excluded jar
| | +- org.springframework.security:spring-security-core:jar:3.2.5.RELEASE:compile
| | \- excluded jar
| | +- excluded jar
| | \- excluded jar
| | \- excluded jar
| | \- com.springsource.insight:insight-annotation:jar:1.8.3.RELEASE:compile
| +- com.thoughtworks.xstream:xstream:jar:1.4.8:compile
| | +- xmlpull:xmlpull:jar:1.1.3.1:compile
| | \- xpp3:xpp3_min:jar:1.1.4c:compile
| +- com.thoughtworks.xstream:xstream-hibernate:jar:1.4.8:compile
| +- org.objectweb.asm.util:asm-util:jar:4.0:compile
| +- net.sf.cglib:cglib:jar:3.0:compile
| +- com.esotericsoftware.kryo:kryo:jar:2.19:compile
| | +- com.esotericsoftware.reflectasm:reflectasm:jar:shaded:1.07:compile
| | | \- org.ow2.asm:asm:jar:4.0:compile
| | \- com.esotericsoftware.minlog:minlog:jar:1.2:compile
| +- org.springframework.integration:spring-integration-core:jar:4.1.0.RELEASE:compile
| | +- org.projectreactor:reactor-core:jar:1.1.4.RELEASE:compile
| | | +- com.goldmansachs:gs-collections:jar:5.1.0:compile
| | | | \- com.goldmansachs:gs-collections-api:jar:5.1.0:compile
| | | +- com.lmax:disruptor:jar:3.2.1:compile
| | | \- io.gatling:jsr166e:jar:1.0:compile
| | +- org.springframework:spring-messaging:jar:4.1.2.RELEASE:compile
| | \- org.springframework.retry:spring-retry:jar:1.1.1.RELEASE:compile
| +- org.springframework.amqp:spring-rabbit:jar:1.4.5.RELEASE:compile
| +- org.springframework.amqp:spring-amqp:jar:1.4.5.RELEASE:compile
| +- org.springframework.security:spring-security-remoting:jar:3.2.5.RELEASE:compile
| +- com.rabbitmq:amqp-client:jar:3.5.3:compile
| \- org.springframework.integration:spring-integration-amqp:jar:4.1.0.RELEASE:compile
+- junit:junit:jar:4.11:test
| \- org.hamcrest:hamcrest-core:jar:1.3:test
+- org.mockito:mockito-core:jar:1.9.5:test
| \- org.objenesis:objenesis:jar:1.2:compile
\- excluded jar
+- excluded jar
\- org.springframework:spring-context-support:jar:4.0.2.RELEASE:compile

知道为什么有时 Jersey 通过 hk2 坚持调用 validation-api-1.1.0-Final 方法,有时按预期调用 1.0.0.GA。
我知道验证是在 Jersey 中自动发现的,有没有办法强制它使用 validation-api-1.0.0.GA 实现?

附言- 我注意到 bean-validation-2.2.0 有一份来自 validation-api-1.1.0.Final 的 javax.validation.* 包的副本(为什么? .

更新:
深入挖掘代码,看起来 jersey-bean-validation:2.6 实际上是针对 validation-api-1.1.0.Final 编译并静态调用
getBootstrapConfiguration() 方法。实际上,在 mvnrepository.com 依赖项中,它可以追溯到 jersey-bean-validation:2.0 版本,在 validation-api-1.1.0.Final 上深化

查看 org.glassfish.jersey.server.validation.internal.ValidationBinder 类
可以看到 private ConfiguredValidator getDefaultValidator() 方法调用了 getBootstrapConfiguration() ;在调用私有(private)方法 getTraversableResolver() 时。

因此,它看起来像是在提供方法中以某种方式我有一个 ContextResolver 的唯一选项,它导致代码在不同的路径上分支,从而使调用无效 getBootstrapConfiguration
public ConfiguredValidator provide() {
ContextResolver contextResolver = this.providers.getContextResolver(ValidationConfig.class, MediaType.WILDCARD_TYPE);
if(contextResolver == null) {
return this.getDefaultValidator();
} else {
//not calling the getBootstrapConfiguration() method
}

我调试了两种情况,一种有效,一种无效。
当服务工作时,我注意到 ValidationBinder 正在注入(inject) org.hibernate.validator.internal.engine.ConfigurationImpl.class 到配置字段
此实现来自 bean-validation-2.2.0 jar 并实现 getBootstrapConfiguration() 方法
当服务不起作用时,我正在注入(inject) ValidationBinder org.hibernate.validator.engine.ConfigurationImpl 到配置字段
它来自 hibernate-validation-4.2.0 jar。

我试图通过将配置绑定(bind)到 org.hibernate.validator.internal.engine.ConfigurationImpl.class 来强制 设置
例如
public class JerseyConfig extends ResourceConfig {

public JerseyConfig() {
register(new AbstractBinder() {
@Override
protected void configure() {
bind(org.hibernate.validator.internal.engine.ConfigurationImpl.class).to(Configuration.class);
}
});
}

但这并没有解决我的问题。

最佳答案

经过我的调查以及我在这里没有得到任何答案(尽管我提出了赏金)而不是在 Jersey 论坛中的事实。
可以假设我只是很幸运,这在 java 7(一直)和 java 8(兼职)中可以正常工作,可能是一些错误/神奇的类路径顺序。

对我有用的是升级到 hibernate-validator 5.0.0 和 validator-api-1.1.0.Final。

关于validation - Jersey 2.6 REST 服务升级到 Java 8 tomcat 8 异常 :java. lang.NoSuchMethodError : javax. validation.Configuration.getBootstrapConfiguration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35910698/

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