问题
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.
回答1:
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.
回答2:
According to this article the jboss-deployment-structure.xml shoudl be placed in 'the top level deployment, in META-INF (or WEB-INF for web deployments)'.
So with your current set-up the things configured in the xml are not applied, so if the xml is put in the right location it might work.
回答3:
javax.validation.constraints.NotBlank
is part of Bean Validation 2.0 and thus Java EE 8. I suspect EAP 7.1 does not support this feature yet.
来源:https://stackoverflow.com/questions/50751653/jboss-eap-7-1-spring-boot-application-no-validator-could-be-found-for-constra