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

匿名 (未验证) 提交于 2019-12-03 01:34:02

问题:

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:

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.



回答2:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!