spring - Why Autowire of class Validator not working but working for GeneralValidator? -
i have came across weird behavior in java class , wanted understand cause of such behavior, since investigating online didn't result similar situation, had ask.
my java program using spring framework has class named validator, it's definition follows:
@component public class validator { ... } now, in many other places in code use class @autowired annotation, like:
@autowired validator validator; when try fire service .war fails error: org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type [com.company.common.validators.validator]
but if add name @component annotation this:
@component("validator") public class validator { ... } it works fine.
why have state name of validator class in @component annotation, when same name? have noticed if change class name else, example: generalvalidator works fine without stating name in @component.
this because of conflict org.springframework.validation.validator (documented here), please note documentation of optional argument @component (here)
the value may indicate suggestion logical component name, turned spring bean in case of autodetected component.
Comments
Post a Comment