2010-10-27 42 views
1

我在JBoss 5.1上遇到了一些使用Hibernate 3.4的問題。 Hibernate 3.4是一個JPA 1.0實現,因此在JBoss 5.1中使用它應該沒問題。事情是JBoss有自己的Hibernate版本,它位於/ common/lib,而我不想使用JBoss提供的版本。我所做的是從該文件夾中刪除了hibernate-annotations.jar,hibernate-commons-annotations.jar,hibernate-core.jar,hibernate-entitymanager.jar,hibernate-jmx.jar和hibernate-validator.jar,我的Hibernate 3.4將進入server/default/lib目錄。我還將hibernate-validator.jar 3.1.0編譯到我的war文件中,因爲它看起來不然,否則JBoss無法識別驗證程序的位置。完成上述所有操作後,我打包了我的war文件並將其部署到deploy文件夾。嘗試在JBoss 5.1中使用hibernate 3.4,但獲取javax.validation.ValidationException:無法找到默認提供者

服務器啓動時沒有問題。但是當我試圖訪問我的Web應用程序時,它會拋出一個錯誤:

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.Http11Processor.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

看起來它仍然無法找到驗證器。但它已經在戰爭檔案中。我已經在碼頭服務器上測試了我的web應用程序,並且它工作正常。我在JBoss配置中做了什麼錯誤?

回答

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.

我認爲,建議的做法是捆綁你想在你的應用程序使用和配置JBoss首先從應用程序加載罐子庫,使用的jboss-web.xml文件,內容如下(見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> 

使用Bean驗證時,我沒有這個測試自己,但在this thread(也this one報道的用戶),他仍然不得不從common/lib更換捆綁驗證。這聽起來很奇怪,我不能確認它是必需的。先嚐試一下。

+0

只有一個驗證器在war文件中。我已經從common/lib中刪除了驗證器。我認爲類加載器應該嘗試從war文件中獲取它,如果它無法在其他地方找到它的話。 – newguy 2010-10-27 01:40:29

+0

@newguy:我不認爲來自common/lib的類可以從您的web應用程序加載某些東西。但是,反過來會起作用。 – 2010-10-27 01:44:51

0

如果有人仍在尋找答案。 我在使用hibernate-validator 3.0.1時遇到了這個問題,我將它改爲4.2.0.Final並且工作正常。

另外,請確保你已安裝validator-api jar

相關問題