Using @Autowired component in custom JSR-303 validator

喜你入骨 提交于 2019-12-04 18:49:27

I solved this for now by ditching Dependency Injection for the Validator class, instead instantiating an instance of AuthenticationFacadeImpl in the constructor. Would still be interesting, though how to combine the use of @Valid in the Controllers with custom validators + @Autowired attributes in the Model without explicitely calling the Validator in the code...

If your validator is instantiated outside the Spring context, then you can use Spring’s AOP @Configurable magic to register it in context and get autowiring work. All what you need is to annotate HasAnyRoleConstraintValidator with @Configurable and enable compile time, or load time aspects weaving.

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