我使用Apache CXF开发了一个项目,并将Hibernate验证部署到IBM应用服务器版本9
我的hibernate设置如下 hibernate-core - 5.2.10.Final org.hibernate.jpa.HibernatePersistenceProvider作为我的jpa提供者
遇到ClassNotFoundException:com.ibm.websphere.persistence.PersistenceProviderImpl
我在使用bean验证的WAS 8.5中没遇到过这个问题。
表示gradle依赖
springFramewokVersion = '4.3.0.RELEASE'
apacheCxfVersion = '3.1.10'
jacksonVersion = '2.8.7'
aspectJVersion = '1.8.9'
compile group: 'org.apache.cxf', name: 'cxf-rt-frontend-jaxrs', version: "${apacheCxfVersion}"
compile group: 'org.apache.cxf', name: 'cxf-rt-rs-client', version: "${apacheCxfVersion}"
compile group: 'org.apache.cxf', name: 'cxf-rt-rs-service-description', version: "${apacheCxfVersion}"
//jackson
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: "${jacksonVersion}"
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: "${jacksonVersion}"
compile group: 'com.fasterxml.jackson.jaxrs', name: 'jackson-jaxrs-json-provider', version: "${jacksonVersion}"
//spring
compile group: 'org.springframework', name: 'spring-web', version: "${springFramewokVersion}"
compile group: 'org.springframework', name: 'spring-aop', version: "${springFramewokVersion}"
compile group: 'org.springframework', name: 'spring-core', version: "${springFramewokVersion}"
compile group: 'org.springframework', name: 'spring-orm', version: "${springFramewokVersion}"
compile group: 'org.springframework', name: 'spring-context', version: "${springFramewokVersion}"
compile group: 'org.springframework', name: 'spring-tx', version: "${springFramewokVersion}"
compile group: 'org.springframework', name: 'spring-webmvc', version: "${springFramewokVersion}"
//aspect
compile group: 'org.aspectj', name: 'aspectjrt', version: "${aspectJVersion}"
compile group: 'org.aspectj', name: 'aspectjweaver', version: "${aspectJVersion}"
//utility
compile group: 'io.jsonwebtoken', name: 'jjwt', version:'0.6.0'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version:'4.5.2'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.7'
providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version:'3.1.0'
compile group: 'org.modelmapper', name: 'modelmapper', version: '0.7.7'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.5'
//persistence
compile group: 'org.hibernate', name: 'hibernate-core', version: '5.2.10.Final'
//testing
compile group: 'junit', name: 'junit', version:'4.12'
compile group: 'org.jmockit', name: 'jmockit', version: '1.21'
compile group: 'org.jmockit', name: 'jmockit-coverage', version: '1.21'
//validation
compile group: 'javax.validation', name: 'validation-api', version: '1.1.0.Final'
compile group: 'javax.el', name: 'javax.el-api', version: '3.0.0'
compile group: 'org.glassfish', name: 'javax.el', version: '3.0.0'
compile group: 'org.hibernate', name: 'hibernate-validator', version: '5.4.1.Final'
//swagger
compile group: 'org.apache.cxf', name: 'cxf-rt-rs-service-description-swagger', version: "${apacheCxfVersion}"
compile group: 'org.webjars', name: 'swagger-ui', version: '3.0.3'
用于控制器
@POST
@Path("/authenticate")
@Consumes(MediaType.APPLICATION_JSON)
public Response authenticateCredentials(@BeanParam BaseRSParams params,
@Valid @RequestBody AuthenticationParams authenticationParams) throws DirectoryServiceException {
ldapService = (ILdapService) getService(LDAP_SERVICE_IMPL + params.getVersion());
ldapService.isUserValid(authenticationParams.getUsername(), authenticationParams.getPassword());
return Response.ok().build();
}
表示持久性xml
<persistence-unit name="cifPersistenceUnit" >
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="hibernate.generate_statistics" value="true"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>
</properties>
</persistence-unit>
用于stacktrace
javax.validation.ValidationException: HV000041: Call to TraversableResolver.isReachable() threw an exception.
org.hibernate.validator.internal.engine.ValidatorImpl.isReachable(ValidatorImpl.java:1620)
org.hibernate.validator.internal.engine.ValidatorImpl.isValidationRequired(ValidatorImpl.java:1596)
org.hibernate.validator.internal.engine.ValidatorImpl.validateMetaConstraint(ValidatorImpl.java:608)
org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:581)
org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForSingleDefaultGroupElement(ValidatorImpl.java:527)
org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:495)
org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:460)
org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:410)
org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraint(ValidatorImpl.java:756)
org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:680)
org.hibernate.validator.internal.engine.ValidatorImpl.validateParametersInContext(ValidatorImpl.java:1117)
org.hibernate.validator.internal.engine.ValidatorImpl.validateParameters(ValidatorImpl.java:301)
org.hibernate.validator.internal.engine.ValidatorImpl.validateParameters(ValidatorImpl.java:255)
org.apache.cxf.validation.BeanValidationProvider.validateParameters(BeanValidationProvider.java:116)
org.apache.cxf.validation.AbstractBeanValidationInterceptor.handleValidation(AbstractBeanValidationInterceptor.java:55)
org.apache.cxf.jaxrs.validation.JAXRSBeanValidationInInterceptor.handleValidation(JAXRSBeanValidationInInterceptor.java:55)
org.apache.cxf.validation.AbstractValidationInterceptor.handleMessage(AbstractValidationInterceptor.java:72)
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:262)
org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234)
org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208)
org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)
org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:180)
org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:299)
org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:218)
javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:274)
com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1235)
com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:779)
com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1124)
com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:4144)
com.ibm.ws.webcontainer.webapp.WebAppImpl.handleRequest(WebAppImpl.java:2208)
com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:1030)
com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1817)
com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:382)
com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:465)
com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:532)
com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:318)
com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:88)
com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1892)
Caused by: javax.persistence.PersistenceException: java.lang.ClassNotFoundException: com.ibm.websphere.persistence.PersistenceProviderImpl
javax.persistence.spi.PersistenceProviderResolverHolder$PersistenceProviderResolverPerClassLoader$CachingPersistenceProviderResolver.loadResolverClasses(PersistenceProviderResolverHolder.java:160)
javax.persistence.spi.PersistenceProviderResolverHolder$PersistenceProviderResolverPerClassLoader$CachingPersistenceProviderResolver.<init>(PersistenceProviderResolverHolder.java:122)
javax.persistence.spi.PersistenceProviderResolverHolder$PersistenceProviderResolverPerClassLoader.getPersistenceProviders(PersistenceProviderResolverHolder.java:80)
javax.persistence.Persistence.getProviders(Persistence.java:69)
javax.persistence.Persistence.access$000(Persistence.java:23)
javax.persistence.Persistence$1.isLoaded(Persistence.java:109)
org.hibernate.validator.internal.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:47)
org.hibernate.validator.internal.engine.resolver.DefaultTraversableResolver.isReachable(DefaultTraversableResolver.java:128)
org.hibernate.validator.internal.engine.resolver.CachingTraversableResolverForSingleValidation.isReachable(CachingTraversableResolverForSingleValidation.java:36)
org.hibernate.validator.internal.engine.ValidatorImpl.isReachable(ValidatorImpl.java:1611)
... 50 more
Caused by: java.lang.ClassNotFoundException: com.ibm.websphere.persistence.PersistenceProviderImpl
java.net.URLClassLoader.findClass(URLClassLoader.java:609)
com.ibm.ws.bootstrap.ExtClassLoader.findClass(ExtClassLoader.java:243)
java.lang.ClassLoader.loadClassHelper(ClassLoader.java:850)
java.lang.ClassLoader.loadClass(ClassLoader.java:829)
com.ibm.ws.bootstrap.ExtClassLoader.loadClass(ExtClassLoader.java:134)
java.lang.ClassLoader.loadClass(ClassLoader.java:809)
com.ibm.ws.classloader.ProtectionClassLoader.loadClass(ProtectionClassLoader.java:62)
com.ibm.ws.classloader.ProtectionClassLoader.loadClass(ProtectionClassLoader.java:58)
com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:619)
java.lang.ClassLoader.loadClass(ClassLoader.java:809)
com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:619)
java.lang.ClassLoader.loadClass(ClassLoader.java:809)
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:619)
at java.lang.ClassLoader.loadClass(ClassLoader.java:809)
at javax.persistence.spi.PersistenceProviderResolverHolder$PersistenceProviderResolverPerClassLoader$CachingPersistenceProviderResolver.loadResolverClasses(PersistenceProviderResolverHolder.java:142)
... 59 more
答案 0 :(得分:0)
在WebSphere Application Server V9.0中,默认的JPA Provider已从WSJPA / OpenJPA切换到EclipseLink。异常堆栈显示您的应用程序正在尝试加载WSJPA JPA提供程序类,如果将EclipseLink设置为JPA提供程序(WebSphere 9中的缺省值),则该类不可见。
如果您想使用WSJPA作为JPA提供程序,可以通过转到管理控制台来切换默认的JPA提供程序 - &gt;展开服务器 - &gt;应用程序服务器 - &gt;选择您的服务器 - &gt;展开容器服务 - &gt;默认Java持久性API设置 - &gt;在JPA规范下,选择2.0并确保将默认持久性提供程序设置为“com.ibm.websphere.persistence.PersistenceProviderImpl”