Fix: Error creating bean with name securityConfig: Unsatisfied dependency expressed - NoSuchBeanDefinitionException: No qualifying bean of type



Error creating bean with name 'securityConfig': 
Unsatisfied dependency expressed through field 'dataConfig'; 
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No qualifying bean of type 'org.code2care.DataConfig' available: 
expected at least 1 bean which qualifies as autowire candidate. 
Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

You get this error due to an issue with Spring Framework related to dependency injection, there seems to be a problem with autowiring a bean of type org.code2care.DataConfig in your SecurityConfig class.

Make sure the below classes are defined correctly.

@Configuration
public class DataConfig {
    @Bean
    public DataConfig dataConfig() {
        return new DataConfig();
    }
}
@SpringBootApplication
@ComponentScan(basePackages = "org.code2care")
public class DataApplication {
    public static void main(String[] args) {
        SpringApplication.run(DataApplication.class, args);
    }
}

Also make sure @Autowired annotation as been added on DataConfig instance.

@Autowired
private DataConfig dataConfig;

And finally, make sure @DependsOn is added on SecurityConfig.

@Configuration
@DependsOn("dataConfig")
public class SecurityConfig {

...
...
-

Facing issues? Have Questions? Post them here! I am happy to answer!


Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

Copyright © Code2care 2023 | Privacy Policy | About Us | Contact Us | Sitemap