ComponentScan code smell? When running unit tests, I get Error creating bean, no qualifying bean of type, even though bean exists in Spring beans list



i have a config class in a config package that looks like this:

package com.x.y.appName.config

@ComponentScan(basePackageClasses = { Application.class })
public class AppConfig {

my project is failing on build within SomeClass that uses the AppConfig bean, saying:

Error creating bean with name 'someClass': Unsatisfied dependency
expressed through field 'appConfig'; nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
qualifying bean of type

But when I stdout print the list of beans Spring is aware of, it lists appConfig there

SomeClass is also in the config package, and looks like this:

package com.x.y.appName.config;

public class SomeClass implements WebMvcConfigurer {

AppConfig appConfig;

but if i add this to SomeClass, it builds fine and all tests pass:


in the past ive never needed to ComponentScan the same package that another bean is also declared in

again to clarify, i can bootRun the app just fine, but this spring error is throwing during build or test. do i need to add something to the unit tests? I dont have unit tests for either of the above classes as they would be too frivolous. So what could be going on? Do I need to annotate other unit tests somewhere?

Continue reading...