Skip to content

<mvc:annotation-driven> does not register javax.validation.Valdiator by default with the application context ? [SPR-6377] #11044

@spring-projects-issues

Description

@spring-projects-issues

Karthik Gurumurthy opened SPR-6377 and commented

javax.validation.Validator doesn't get injected with mvc:annotation-driven/

@Controller
class MyController{

@Autowired
private javax.validation.Validator validator;
}

stack trace >>>
Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.validation.Validator com.etrade.af.account.controller.AccountController.validator; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [javax.validation.Validator] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

It works if I explicitly declare LocalValidatorFactoryBean in my application context though.

mvc:annotation-driven/

<!-- Explicitly Configure JSR-303 Declarative Validation -->

<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />

I guess the mvc namespacehandler doesn't register this class with the bean registry by default?


Affects: 3.0 RC2

Referenced from: commits 4efa91d

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions