org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'au.edu.open.sde.validator.PasswordMatchValidator' is defined

Spring JIRA | Derek Clarkson | 7 years ago
  1. 0

    We have written a custom validator and annotation. When we attempt to inject a value provided by a PropertyPlaceholderConfigurer, an exception is triggered. We can successfully inject bean references, which leads us to believe that there is an issue around injecting values. The following are the distilled segments of the code to show the setup and exception. {code:title=Spring config} ... <context:annotation-config /> <mvc:annotation-driven /> <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" /> ... {code} {code:title=Annotation PasswordMatch.java} @Target( { TYPE, ANNOTATION_TYPE }) @Retention(RUNTIME) @Constraint(validatedBy = PasswordMatchValidator.class) @Documented public @interface PasswordMatch { String message() default "{au.edu.open.website.PasswordMatchValidation}"; Class<?>[] groups() default {}; Class<? extends Payload>[] payload() default {}; String field(); } {code} {code:title=Validator PasswordMatchValidator.java} public class PasswordMatchValidator implements ConstraintValidator<PasswordMatch, Object> { // This works and the properties bean is inject on each validation execution. @Autowired private SystemProperties props; // This does not work and triggers an exception. @Value("$host{file.storage.directory}") private String dir; public void initialize(final PasswordMatch constraintAnnotation) { fieldName = constraintAnnotation.field(); } // ... Rest of validator code goes here. } {code} Here is the exception that is thrown when validating: {code:title=Thrown exception} org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'au.edu.open.sde.validator.PasswordMatchValidator': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.lang.String au.edu.open.sde.validator.PasswordMatchValidator.dir; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'au.edu.open.sde.validator.PasswordMatchValidator' is defined at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1055) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:286) at org.springframework.validation.beanvalidation.SpringConstraintValidatorFactory.getInstance(SpringConstraintValidatorFactory.java:50) at org.hibernate.validator.engine.ConstraintTree.createAndInitializeValidator(ConstraintTree.java:192) at org.hibernate.validator.engine.ConstraintTree.getInitializedValidator(ConstraintTree.java:171) at org.hibernate.validator.engine.ConstraintTree.validateConstraints(ConstraintTree.java:113) at org.hibernate.validator.metadata.MetaConstraint.validateConstraint(MetaConstraint.java:121) at org.hibernate.validator.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:334) at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForRedefinedDefaultGroup(ValidatorImpl.java:278) at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:260) at org.hibernate.validator.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:213) at org.hibernate.validator.engine.ValidatorImpl.validate(ValidatorImpl.java:119) at org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:74) at org.springframework.validation.DataBinder.validate(DataBinder.java:688) ... {code}

    Spring JIRA | 7 years ago | Derek Clarkson
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'au.edu.open.sde.validator.PasswordMatchValidator' is defined
  2. 0

    We have written a custom validator and annotation. When we attempt to inject a value provided by a PropertyPlaceholderConfigurer, an exception is triggered. We can successfully inject bean references, which leads us to believe that there is an issue around injecting values. The following are the distilled segments of the code to show the setup and exception. {code:title=Spring config} ... <context:annotation-config /> <mvc:annotation-driven /> <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" /> ... {code} {code:title=Annotation PasswordMatch.java} @Target( { TYPE, ANNOTATION_TYPE }) @Retention(RUNTIME) @Constraint(validatedBy = PasswordMatchValidator.class) @Documented public @interface PasswordMatch { String message() default "{au.edu.open.website.PasswordMatchValidation}"; Class<?>[] groups() default {}; Class<? extends Payload>[] payload() default {}; String field(); } {code} {code:title=Validator PasswordMatchValidator.java} public class PasswordMatchValidator implements ConstraintValidator<PasswordMatch, Object> { // This works and the properties bean is inject on each validation execution. @Autowired private SystemProperties props; // This does not work and triggers an exception. @Value("$host{file.storage.directory}") private String dir; public void initialize(final PasswordMatch constraintAnnotation) { fieldName = constraintAnnotation.field(); } // ... Rest of validator code goes here. } {code} Here is the exception that is thrown when validating: {code:title=Thrown exception} org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'au.edu.open.sde.validator.PasswordMatchValidator': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.lang.String au.edu.open.sde.validator.PasswordMatchValidator.dir; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'au.edu.open.sde.validator.PasswordMatchValidator' is defined at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1055) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:286) at org.springframework.validation.beanvalidation.SpringConstraintValidatorFactory.getInstance(SpringConstraintValidatorFactory.java:50) at org.hibernate.validator.engine.ConstraintTree.createAndInitializeValidator(ConstraintTree.java:192) at org.hibernate.validator.engine.ConstraintTree.getInitializedValidator(ConstraintTree.java:171) at org.hibernate.validator.engine.ConstraintTree.validateConstraints(ConstraintTree.java:113) at org.hibernate.validator.metadata.MetaConstraint.validateConstraint(MetaConstraint.java:121) at org.hibernate.validator.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:334) at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForRedefinedDefaultGroup(ValidatorImpl.java:278) at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:260) at org.hibernate.validator.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:213) at org.hibernate.validator.engine.ValidatorImpl.validate(ValidatorImpl.java:119) at org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:74) at org.springframework.validation.DataBinder.validate(DataBinder.java:688) ... {code}

    Spring JIRA | 7 years ago | Derek Clarkson
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'au.edu.open.sde.validator.PasswordMatchValidator' is defined
  3. 0

    @PostConstuct does not appear to work and @autowire gives an error

    Stack Overflow | 7 months ago | T.Nee
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.nikki.spring3.beansit.HelloWorldService] 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)}
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    No bean named '' is defined (Frameworks forum at Coderanch)

    coderanch.com | 6 months ago
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named '' is defined

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. org.springframework.beans.factory.NoSuchBeanDefinitionException

      No bean named 'au.edu.open.sde.validator.PasswordMatchValidator' is defined

      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues()
    2. Spring Beans
      AbstractAutowireCapableBeanFactory.createBean
      1. org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
      2. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1055)
      3. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
      4. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
      5. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:286)
      5 frames
    3. Spring Context
      SpringConstraintValidatorFactory.getInstance
      1. org.springframework.validation.beanvalidation.SpringConstraintValidatorFactory.getInstance(SpringConstraintValidatorFactory.java:50)
      1 frame
    4. Vaadin
      ConstraintTree.validateConstraints
      1. org.hibernate.validator.engine.ConstraintTree.createAndInitializeValidator(ConstraintTree.java:192)
      2. org.hibernate.validator.engine.ConstraintTree.getInitializedValidator(ConstraintTree.java:171)
      3. org.hibernate.validator.engine.ConstraintTree.validateConstraints(ConstraintTree.java:113)
      3 frames
    5. Embedded GlassFish Web
      MetaConstraint.validateConstraint
      1. org.hibernate.validator.metadata.MetaConstraint.validateConstraint(MetaConstraint.java:121)
      1 frame
    6. Vaadin
      ValidatorImpl.validate
      1. org.hibernate.validator.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:334)
      2. org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForRedefinedDefaultGroup(ValidatorImpl.java:278)
      3. org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:260)
      4. org.hibernate.validator.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:213)
      5. org.hibernate.validator.engine.ValidatorImpl.validate(ValidatorImpl.java:119)
      5 frames
    7. Spring Context
      DataBinder.validate
      1. org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:74)
      2. org.springframework.validation.DataBinder.validate(DataBinder.java:688)
      2 frames