Tuesday, May 1, 2018

Spring changes finding beans from version 4.3 to 5

Leave a Comment

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?

3 Answers

Answers 1

Seems a bug of Spring 5.0.5, and has been fixed in 5.0.6, see this Null check needed in AnnotationUtils.getAnnotation

Answers 2

Please checkout the implementations of respect interface, If it is not there provide implementation. If implementation is there please check whether they have class level annotation as @Component or any specific annotations. For info related auto wiring read this.

Answers 3

it seems that your dependencies are a mess, try to check theme with mvn dependency:tree if you use maven and fix version conflicts

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment