我们有一场 war ,它通过基于hibernate-4.2.7验证(实现validate-api-1.0.0.GA)的验证来公开jersey 2.6之上的其余服务。
在我们升级到Java 8和tc-server 3.1.X之前,一切工作正常。
升级到Java 8后,验证api中的某些内容似乎已损坏。
我们得到
当我们发送休养申请表时,客户。
最奇怪的是,这种行为不是由
当我从依赖项中添加或删除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
任何想法为什么有时通过hk2的jersey都坚持按预期的方式调用validation-api-1.1.0-Final方法,有时又调用1.0.0.GA。
我知道验证是在jersey中自动发现的,有没有一种方法可以强制其使用validation-api-1.0.0.GA实现?
P.S. -我注意到bean-validation-2.2.0包含来自validation-api-1.1.0.Final的javax.validation。*包的副本(为什么?),但是正如您从依赖关系树中看到的那样,我们特别排除了它。
更新:
深入研究代码看起来像jersey-bean-validation:2.6实际上是针对validation-api-1.1.0进行编译的。最终并静态调用
getBootstrapConfiguration()方法。实际上,在mvnrepository.com依赖项中,它可以追溯到Verification-api-1.1.0上加深的jersey-bean-validation:2.0版本。
查看org.glassfish.jersey.server.validation.internal.ValidationBinder类
您可以看到
private ConfiguredValidator getDefaultValidator()
方法调用getBootstrapConfiguration()
;在调用私有(private)方法getTraversableResolver()
时。因此,看起来好像在provide方法中以某种方式存在的唯一选项是我有一个
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(兼职)中都能正常工作,可能是某些bug/神奇的类路径顺序所致。
对我有用的是升级到hibernate-validator 5.0.0和validator-api-1.1.0.Final。
关于validation - Jersey 2.6 REST服务已升级到Java 8 tomcat 8异常:java. lang.NoSuchMethodError : javax.验证.Configuration.getBootstrapConfiguration,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35910698/