开发者

Try to use hibernate 3.4 in JBoss 5.1 but gets javax.validation.ValidationException: Unable to find a default provider

开发者 https://www.devze.com 2023-01-22 07:07 出处:网络
I\'ve come across some problems using Hibernate 3.4 on JBoss 5.1. Hibernate 3.4 is a JPA 1.0 implementation so it should be fine to be used in JBoss 5.1. The thing is JBoss has its own version of Hibe

I've come across some problems using Hibernate 3.4 on JBoss 5.1. Hibernate 3.4 is a JPA 1.0 implementation so it should be fine to be used in JBoss 5.1. The thing is JBoss has its own version of Hibernate, which is located at /common/lib whereas I don't want to use the version provided by JBoss. What I did was that I removed the hibernate-annotations.jar, hibernate-commons-annotations.jar, hibernate-core.jar, hibernate-entitymanager.jar, hibernate-jmx.jar and hibernate-validator.jar from that folder and put my Hibernate 3.4 jars into server/default/lib directory. I also compiled hibernate-validator.jar 3.1.0 into my war file because it seems otherwise JBoss cannot recognize where the validator is. After I have done all the above, I packaged my war file and deployed it to the deploy folder.

The server started with no issue. But when I tried to access my web application it throws an error:

2010-10-27 10:55:13,416 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost]] (http-172.16.10.211-80-1) Exception Processing ErrorPage[exceptionType=java.lang.Exception, location=/app/uncaughtException] javax.servlet.ServletException: Servlet.init() for servlet roodummy threw exception at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1089) at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:777) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:607) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:446) at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:382) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:310) at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:416) at org.apache.catalina.core.StandardHostValve.throwable(StandardHostValve.java:270) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330) at org.apache.coyote.http11.H开发者_开发百科ttp11Processor.process(Http11Processor.java:829) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:662) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0': Invocation of init method failed; nested exception is javax.validation.ValidationException: Unable to find a default provider at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1412) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:872) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423) at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442) at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458) at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339) at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306) at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127) at javax.servlet.GenericServlet.init(GenericServlet.java:212) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1048) ... 16 more Caused by: javax.validation.ValidationException: Unable to find a default provider at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:264) at org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet(LocalValidatorFactoryBean.java:161) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1469) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1409) ... 32 more

It looks like it still cannot find the validator. But it is already in the war file. I have tested my web app in a jetty server and it worked fine. What have I done wrong in the JBoss configuration?


The thing is JBoss has its own version of Hibernate, which is located at /common/lib whereas I don't want to use the version provided by JBoss.

I think that the recommended approach would be to bundle the libs you want to use in your application and to configure JBoss to load jars from your application first, using a jboss-web.xml with the following content (see ClassLoadingConfiguration):

<jboss-web>
   <class-loading java2ClassLoadingCompliance="false">
    <loader-repository>
        unique.packege.name:archive=your_project.war
        <loader-repository-config>
            java2ParentDelegation=false
        </loader-repository-config>
    </loader-repository>
   </class-loading>
</jboss-web>

I've not tested this myself when using Bean Validation but a user reported in this thread (and also this one) he still had to replace the bundled validator from common/lib. This sounds strange and I can't confirm it's required. Try without first.


In case anyone is still looking for an answer. I had this problem when I was using hibernate-validator 3.0.1 I changed it to 4.2.0.Final and it works fine.

also, make sure you have validator-api jar installed

0

精彩评论

暂无评论...
验证码 换一张
取 消