I have a large spring applications using annotations that works fine in spring 4.3.13, and am looking to update to spring 5. I am getting all kinds of failures wiring beans, which look like the typical:
Unsatisfied dependency expressed through field 'pcoDAO'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.acme.dao.impl.contracts.PotentialChangeOrderDAO' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
turning on spring debug logging, only nets this additional line
Failed to meta-introspect annotation interface org.springframework.beans.factory.annotation.Autowired: java.lang.NullPointerException
It's not like all @Autowired fields fail, just this one (so far). The bean is specified by an interface, and the implementation is in a sub package of the interface, but again this worked before. The interface's package is specified directly in the context:component-scan base-package="com.acme.package.of.interface"
Again this works fine in 4.3.13, and the only change is spring being upgraded to 5.0.5-RELEASE.
Are they any known changes to how spring finds beans? or any documentation about this?
Spring Boot 2.7. 5 requires Java 8 and is compatible up to and including Java 19. Spring Framework 5.3. 23 or above is also required.
@Component is a class-level annotation, but @Bean is at the method level, so @Component is only an option when a class's source code is editable. @Bean can always be used, but it's more verbose. @Component is compatible with Spring's auto-detection, but @Bean requires manual class instantiation.
If you define two beans of same class, without different bean id or qualifiers ( identifier) , Spring container will not be able to understand which bean to be loaded , if you try to access the bean by passing the classname and you will get NoUniqueBeanDefinitionException as there are two qualifying TestBean.
@Bean is a method-level annotation and a direct analog of the XML <bean/> element. The annotation supports most of the attributes offered by <bean/> , such as: init-method , destroy-method , autowiring , lazy-init , dependency-check , depends-on and scope .
Seems a bug of Spring 5.0.5, and has been fixed in 5.0.6, see this Null check needed in AnnotationUtils.getAnnotation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With