Spring Bean Not Found

no qualifying bean of type
required a bean of type that could not be found
consider defining a bean of type in your configuration
spring boot bean is not created
not able to create bean in spring boot
org springframework beans factory annotation autowired(required=true in spring boot)
required a bean of type 'java lang string that could not be found
spring boot repository bean not found

I have this project hierarchy:

A SpringConfiguration.java file with one Bean (SoapServiceBean). A LoggerUtilsConfiguration.java with two beans (ConfigManager and LoggerManager).

SpringConfiguration imports LoggerUtilsConfigueration with an @Import.

The code:

@Configuration
@Import({com.myApp.LoggerUtilsConfiguration.class})
public class SpringConfiguration {

    @Lazy
    @Bean(name = "soapServiceBean")
    @Scope(BeanDefinition.SCOPE_PROTOTYPE)
    public SoapServiceBean soapServiceBeanInit(
            @Qualifier("configManager") ConfigManager  configManager ,
            @Qualifier("loggerManager") LoggerManager loggerManager) 
            throws ServiceException, SystemException {

        SoapServiceBean service = new SoapServiceBean();
        service.setConfigManager(configManager);
        service.setLoggerManager(loggerManager);

        return service; 
    }

}

@Configuration
public class LoggerUtilsConfiguration {

    @Bean(name = "configManager")
    @Scope(BeanDefinition.SINGLETON)
    public ConfigManager configManagerInit() {

        ConfigManager cManager = new ConfigManager();

        return cManager; 
    }

    @Bean(name = "loggerManager")
    @Scope(BeanDefinition.SINGLETON)
    public LoggerManager loggerManagerInit() {

        LoggerManager cManager = new LoggerManager();

        return cManager; 
    }

}

My problema is that, "configManager" is a valid bean, but loggerManager throws this Exception:

No qualifying bean of type [com.myApp.LoggerManager] found for dependency: 
    expected at least 1 bean which qualifies as autowire candidate for this dependency. 
    Dependency annotations: {@org.springframework.beans.factory.annotation.Qualifier(value=loggerManager)} 

Is very Strange, because If I copy the loggerManager Bean method into the main @Configuration class, the app starts with no problem and loggerManager is started with no problem.

"LoggerUtilsConfiguration" is not part of my App, is a Maven dependency external jar from another dev team. I have decompiled it and I cannot see anything strange, "configManager" and "loggerManager" has the same annotations with the same values except the bean name.

Any idea?


If the 2 managers are singletons you can @Autowired them in.

If there is an existing bean called loggerManager of a different type then it wouldn't find yours, but it depends on how your classpath is set up.

@Configuration
@Import({com.myApp.LoggerUtilsConfiguration.class})
public class SpringConfiguration {

    @Autowired
    ConfigManager configManager;
    @Autowired
    LoggerManager loggerManager;

    @Lazy
    @Bean(name = "soapServiceBean")
    @Scope(BeanDefinition.SCOPE_PROTOTYPE)
    public SoapServiceBean soapServiceBeanInit() 
            throws ServiceException, SystemException {

        SoapServiceBean service = new SoapServiceBean();
        service.setConfigManager(configManager);
        service.setLoggerManager(loggerManager);

        return service; 
    }

}

Java: How to fix Spring @Autowired annotation not working issues , initializeBean( bean, "bean" );. initializeBean processes the PostConstruct annotation. There is some discussion though if this does not break the  If however the bean is injected by the actual class, then Spring will not find a bean definition that matches the class – since the proxy does not actually extend the class. A very common reason the bean may be proxied is the Spring transactional support – namely beans that are annotated with @Transactional.


Try to use @DependsOn:

    @Lazy
    @Bean(name = "soapServiceBean")
    @DependsOn({ "configManager", "loggerManager" })
    @Scope(BeanDefinition.SCOPE_PROTOTYPE)
    public SoapServiceBean soapServiceBeanInit(
            @Qualifier("configManager") ConfigManager  configManager ,
            @Qualifier("loggerManager") LoggerManager loggerManager) 
            throws ServiceException, SystemException {

        SoapServiceBean service = new SoapServiceBean();
        service.setConfigManager(configManager);
        service.setLoggerManager(loggerManager);

        return service; 
    }

Spring NoSuchBeanDefinitionException, 2. Cause: No Qualifying Bean of Type […] Found for Dependency. Manually add the bean to the Spring context If you not only want the Autowired annotation to be processed inside the bean, but also make the new instance available to be autowired to other instances, it needs to be present in the SpringApplicationContext.


Try providing autowire annotation to properly enable constructor injection like :

@Configuration
@Import({com.myApp.LoggerUtilsConfiguration.class})
public class SpringConfiguration {

    @Lazy
    @Autowired
    @Bean(name = "soapServiceBean")
    @Scope(BeanDefinition.SCOPE_PROTOTYPE)
    public SoapServiceBean soapServiceBeanInit(
            @Qualifier("configManager") ConfigManager  configManager ,
            @Qualifier("loggerManager") LoggerManager loggerManager) 
            throws ServiceException, SystemException {

        SoapServiceBean service = new SoapServiceBean();
        service.setConfigManager(configManager);
        service.setLoggerManager(loggerManager);

        return service; 
    }

}

The @Qualifier annotation is used to resolve the bean based on names while the @Autowired annotation provides constructor injection of beans. The @Bean annotation should support constructor injection without the need for @Autowired

Spring BeanCreationException, Let's start with a simple example, a bean which does not require the use of to a class it will get auto-detected and created by Spring allowing it to be excluded  Now(in Spring Boot 2.0.0.M6) I provided a custom UserDetailsService bean, and I have to expose the AuthenticationManager bean by overriding authenticationManagerBean myself. Ok, this is not a big problem, if this is the purpose of this change, I accept it.


Solved.

My problem is the WebSphere, that store an old version of the third party JAR.

\was\wasprofiles\wp_profile80\installedApps\GUUPZN00Cell\MY-APP.ear\lib\LOGGER-LIB-1.0.0.jar
\was\wasprofiles\wp_profile80\installedApps\GUUPZN00Cell\MY-APP.ear\lib\LOGGER-LIB-1.0.1.jar

The version "1.0.0" LOGGER-LIB doesn't contains the bean "loggerManager" and WebSphere is loading this version of the library. It seems that the file was blocked when websphere try to delete it. I had to stop the server to delete it properly.

Playing around with Spring Bean Configuration, If no such type is found, an error is thrown. But, what if there are two or more beans for same class type. In this case spring will not be able to choose correct bean  Spring Beans License: Apache 2.0: Categories: Dependency Injection: Tags: beans spring dependency-injection: Used By: 5,219 artifacts: Central (175) Atlassian 3rd-P


Spring Bean Autowiring - @Autowired, In this post, we will see about an exception: No qualifying bean of type. Exceptions are least expected but you might get it while working with  Spring - Bean Definition - The objects that form the backbone of your application and that are managed by the Spring IoC container are called beans. A bean is an object that is instantiat


No qualifying bean of type in Spring or Spring Boot, @Configuration public class AppConfig { @Bean public MyBean myBean() { // instantiate, In particular, if a single constructor is present autowiring semantics will be @Configuration classes may not only be bootstrapped using component  Any @Bean annotated method, which is not public (i.e. with protected or default visibility), will create a 'hidden' bean. Note that due to technical limitations, private @Bean methods are not supported. In the example above, mainBean has been configured with both publicBean and hiddenBean. However, since the latter is (as the name imply) hidden


Configuration (Spring Framework 5.2.7.RELEASE API), Working against an in-memory datasource in thrown, because the container could not find the Spring bean named  Spring can automatically scan a package for beans if component scanning is enabled. @ComponentScan configures which packages to scan for classes with annotation configuration . We can specify the base package names directly with one of the basePackages or value arguments ( value is an alias for basePackages ):