1

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

package com.x.y.appName.config

@ComponentScan(basePackageClasses = { Application.class })
@Configuration
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;

@Configuration
public class SomeClass implements WebMvcConfigurer {

@Autowired
AppConfig appConfig;

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

@ComponentScan("com.x.y.appName.config")

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?

heug
  • 982
  • 2
  • 11
  • 23
  • 1
    something related https://stackoverflow.com/questions/24130166/componentscan-basepackageclasses-vs-componentscan-basepackages-to-register-a-sin – Ryuzaki L Oct 07 '19 at 15:33
  • @Deadpool not really...? – heug Oct 07 '19 at 15:53
  • Is the Application class annotated with @Component ? – Anish B. Oct 07 '19 at 16:01
  • @AnishB. no its annotated with "@SpringBootApplication" ... i thought this achieved what "@Component" does and then some – heug Oct 07 '19 at 16:19
  • @AnishB. ive written many spring apps and never once annotated the main class with "@Component" ... anyway, this did not solve or change anything, i still need to component scan in the same package for build to pass, which really makes no sense to me – heug Oct 07 '19 at 16:57

0 Answers0