Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JBoss EAP 7.1 + Spring Boot Application: No validator could be found for constraint 'javax.validation.constraints.NotBlank'

I'm attempting to deploy a Spring Boot (2.0.2) application on JBoss EAP 7.1 server.

The code that's causing the problem is:

import javax.validation.constraints.NotBlank;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

@Component
@Validated
public class AppProperties {

  @NotBlank
  private String name;

When the application is deployed on JBoss I get the following exception:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
16:44:25,861 ERROR [org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter] (ServerService Thread Pool -- 6 7)

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to bind properties under 'app' to com.example.security.config.AppProperties:

    Property: app.contextpath
    Value: /api
    Origin: class path resource [application.yml]:5:18
    Reason: HV000030: No validator could be found for constraint 'javax.validation.constraints.NotBlank' validating type 'java.lang.String'. Check configuration for 'name'

Action:

Update your application's configuration

I've tried adding the file jboss-deployment-structure.xml with the following contents to WEB-INF/classes:

<jboss-deployment-structure>
  <ear-subdeployments-isolated>true</ear-subdeployments-isolated>
  <deployment>
    <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>
  </deployment>
</jboss-deployment-structure>

But, no luck. What's the workaround? Thanks in advance.

like image 409
Tora Tora Tora Avatar asked Jun 08 '18 00:06

Tora Tora Tora


1 Answers

Even though this question is a year old, I ran into the same issue and couldn't find a solution.

This, I know, will work for Spring Boot 2.1.x and JBoss 7.1, not sure about versions before that.

We obviously need to exclude org.hibernate.validator and javax.validation.api. What wasn't clear is that we also need to exclude the javax.faces.api (it has a transitive dependency on javax.validation.api). Excluding that javax.faces causes JBoss to fail on start up due to missing jsf libraries. We can then simply exclude the jsf subsystem.

<jboss-deployment-structure>
    <deployment>
        <exclude-subsystems>
            <subsystem name="jsf" />
        </exclude-subsystems>
        <exclusions>
            <module name="javax.validation.api" />
            <module name="javax.faces.api" />
            <module name="org.hibernate.validator" />
        </exclusions>
    </deployment>
</jboss-deployment-structure>

Assuming you don't need JSF from jboss, this should work.

like image 149
John Vint Avatar answered Oct 29 '22 02:10

John Vint