org.springframework.beans.factory.NoSuchBeanDefinitionException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • 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}
    via by Derek Clarkson,
  • 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}
    via by Derek Clarkson,
  • Autowiring More than One DataSource in Spring
    via Stack Overflow by Malvon
    ,
    • 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)

    Users with the same issue

    Unknown visitor
    Unknown visitor1 times, last one,