代码之家  ›  专栏  ›  技术社区  ›  Dimitrios K.

如何禁用javax.validation。JBoss 6.4中的api

  •  4
  • Dimitrios K.  · 技术社区  · 8 年前

    类似的问题:

    How to use bean validation 1.1 in JBoss EAP 6.4.0?

    How to change bean-validation version on jboss EAP 6.3?

    Can you use bean validation 1.1 (JSR 349) in JBoss EAP 6.4.4?

    如果我们可以在JBoss 6.x中使用Bean Validation 1.1,似乎存在一些不确定性。

    我当前的jboss-deployment-structure.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
      <deployment>
        <dependencies>
          <!-- list of modules taken from https://access.redhat.com/articles/1122333 -->
          <module name="javax.activation.api" />
          <module name="javax.annotation.api" />
          <module name="javax.ejb.api" />
          <module name="javax.el.api" />
          <module name="javax.enterprise.api" />
          <module name="javax.enterprise.deploy.api" />
          <module name="javax.faces.api" />
          <module name="javax.inject.api" />
          <module name="javax.interceptor.api" />
          <module name="javax.jms.api" />
          <module name="javax.jws.api" />
          <module name="javax.mail.api" />
          <module name="javax.management.j2ee.api" />
          <module name="javax.persistence.api" />
          <module name="javax.resource.api" />
          <module name="javax.rmi.api" />
          <module name="javax.security.auth.message.api" />
          <module name="javax.security.jacc.api" />
          <module name="javax.servlet.api" />
          <module name="javax.servlet.jsp.api" />
          <module name="javax.servlet.jstl.api" />
          <module name="javax.transaction.api" />
          <!--<module name="javax.validation.api" />-->
          <module name="javax.ws.rs.api" />
          <module name="javax.wsdl4j.api" />
          <module name="javax.xml.bind.api" />
          <module name="javax.xml.jaxp-provider" />
          <module name="javax.xml.registry.api" />
          <module name="javax.xml.rpc.api" />
          <module name="javax.xml.soap.api" />
          <module name="javax.xml.stream.api" />
          <module name="javax.xml.ws.api" />
          <module name="javax.api" />
        </dependencies>
        <exclusions>
          <module name="javaee.api" />
          <module name="org.hibernate.validator" />
        </exclusions>
      </deployment>
    </jboss-deployment-structure>
    

    我在.ear中绑定了以下依赖项:

    <dependency>
      <groupId>javax.validation</groupId>
      <artifactId>validation-api</artifactId>
      <version>1.1.0.Final</version>
    </dependency>
    
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-validator</artifactId>
      <version>5.2.2.Final</version>
    </dependency>
    

    但我得到了以下堆栈跟踪:

    14:09:44,085 WARN  [org.jboss.resteasy.plugins.validation.hibernate.AbstractValidatorContextResolver] (AFP-HTTP-96) Unable to load Validation support: javax.validation.ValidationException: Unable to find provider: class org.hibernate.validator.HibernateValidator
    at javax.validation.Validation$ProviderSpecificBootstrapImpl.configure(Validation.java:223) [validation-api-1.0.0.GA-redhat-3.jar:1.0.0.GA-redhat-3]
    at org.jboss.resteasy.plugins.validation.hibernate.AbstractValidatorContextResolver.getGeneralValidator(AbstractValidatorContextResolver.java:40) [resteasy-hibernatevalidator-provider-3.0.9.Final.jar:]
    at org.jboss.resteasy.plugins.validation.hibernate.AbstractValidatorContextResolver.getContext(AbstractValidatorContextResolver.java:54) [resteasy-hibernatevalidator-provider-3.0.9.Final.jar:]
    at org.jboss.resteasy.plugins.validation.hibernate.ValidatorContextResolverCDI.getContext(ValidatorContextResolverCDI.java:16) [resteasy-hibernatevalidator-provider-3.0.9.Final.jar:]
    at org.jboss.resteasy.cdi.JaxrsInjectionTarget.validate(JaxrsInjectionTarget.java:113) [resteasy-cdi-3.0.9.Final.jar:]
    at org.jboss.resteasy.cdi.JaxrsInjectionTarget.inject(JaxrsInjectionTarget.java:67) [resteasy-cdi-3.0.9.Final.jar:]
    at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:297) [weld-core-1.1.31.Final-redhat-1.jar:1.1.31.Final-redhat-1]
    at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:68) [weld-core-1.1.31.Final-redhat-1.jar:1.1.31.Final-redhat-1]
    at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:626) [weld-core-1.1.31.Final-redhat-1.jar:1.1.31.Final-redhat-1]
    at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:653) [weld-core-1.1.31.Final-redhat-1.jar:1.1.31.Final-redhat-1]
    at org.jboss.resteasy.cdi.CdiConstructorInjector.construct(CdiConstructorInjector.java:64) [resteasy-cdi-3.0.9.Final.jar:]
    at org.jboss.resteasy.cdi.CdiConstructorInjector.construct(CdiConstructorInjector.java:69) [resteasy-cdi-3.0.9.Final.jar:]
    at org.jboss.resteasy.plugins.server.resourcefactory.POJOResourceFactory.createResource(POJOResourceFactory.java:52) [resteasy-jaxrs-3.0.9.Final.jar:]
    at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:236) [resteasy-jaxrs-3.0.9.Final.jar:]
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356) [resteasy-jaxrs-3.0.9.Final.jar:]
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179) [resteasy-jaxrs-3.0.9.Final.jar:]
    at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) [resteasy-jaxrs-3.0.9.Final.jar:]
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) [resteasy-jaxrs-3.0.9.Final.jar:]
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) [resteasy-jaxrs-3.0.9.Final.jar:]
     ...
    

    如您所见,验证API是validation-API-1.0.0.GA-redhat-3.jar:1.0.0GA-redhart-3,这意味着JBoss绑定模块实际上没有从类路径中删除。是我做错了什么,还是它是一个不允许我删除javax.validation的bug。应用程序编程接口?我是否需要将更多的模块替换为手动依赖项(例如resteasy)?

    3 回复  |  直到 7 年前
        1
  •  10
  •   Jeremy    8 年前

    我已经验证了Redhat支持人员给出的答案-

    您可以排除JBoss提供的javax。通过排除jaxrs子系统来验证JBoss EAP6中的api类。

    除了排除验证类本身之外,还应排除依赖于它们的模块。因此,jboss部署结构的排除部分。xml应该如下所示:

    <exclude-subsystems>
      <subsystem name="jaxrs"/>
    </exclude-subsystems>
    <exclusions>
      <module name="javaee.api"/>
      <module name="javax.validation.api"/>
      <module name="javax.faces.api"/>
      <module name="org.hibernate.validator"/>
    </exclusions>
    

    *注意-排除javaee模块限制了RedHat的可用支持

        2
  •  3
  •   CoolBeans Jeremy    8 年前

    JBoss EAP 6.x是一个JEE6实现容器。还要记住,更改JBoss EAP6附带的bean验证模块会破坏支持的部分。

    Bean验证是JEE7规范的一部分。您需要升级到 JBoss EAP7 或使用 WildFly 9 or 10 来自社区的。它们都实现了JEE7规范,其中包括Bean Validation 1.1。

        3
  •  1
  •   cabaji99    7 年前

    对于jboss 6.2,我想使用cxf和bean验证1.1,前面的答案对我来说不起作用,为了使它起作用,我必须首先排除所有依赖项,然后再次添加javee。不包括导入javax包的api,如下所示:

    <exclusions>
                <module name="javaee.api"/>
                <module name="javax.validation.api"/>
                <module name="javax.faces.api"/>
                <module name="javax.faces.api" slot="1.2"/>
                <module name="org.hibernate.validator"/>
    
    
            </exclusions>
            <dependencies>
                <module name="javaee.api">
                    <imports>
                        <exclude-set>
                            <path name="javax/ws/rs"/>
                            <path name="javax/ws/rs/core"/>
                            <path name="javax/ws/rs/ext"/>
                            <path name="javax/validation"/>
                            <path name="javax/validation/bootstrap"/>
                            <path name="javax/validation/spi"/>
                            <path name="javax/validation/constraints"/>
                            <path name="javax/validation/groups"/>
                            <path name="javax/validation/metadata"/>
                        </exclude-set>
                    </imports>
                </module>
    
            </dependencies>
    

    然后重复我耳朵的次级部署。