Tag Archives: ioc

[Solved] Error getting bean using springboot: no qualifying bean of type ‘xxx’ available

Recently, I encountered a bug in my work.
the project uses springboot, and uses springcontexthloder, getBean (); No qualifying bean of type ‘xxx’ available

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.tension.web.disabledevaluate.service.DisabledEvaluateService' available

Generally, this error indicates that there is no bean available. Check the code carefully to ensure that this class exists and is injected into spring correctly

Controller:

 public Map loadForm(String round,String instanceId) {
 		//error
        DisabledEvaluateService disabledEvaluateService = SpringContextHolder.getBean(DisabledEvaluateService.class);
 }

Service:

@Service
@Transactional(readOnly = true)
public class DisabledEvaluateService extends CrudService<DisabledEvaluateDao, DisabledEvaluate> {
    public DisabledEvaluate getByBjId(Map map){
        return dao.getByBjIdOrInstanceId(map);
    }

After several hours of exploration, we finally found the information on the Internet because we used the devtools hot deployment plug-in. As a result, when the program starts, we use the classloader rewritten by the devtools hot deployment plug-in instead of the Java default classloader. As a result, some classes may not be loaded correctly, resulting in the inability to obtain beans.

Solution:
this error can be solved without using hot deployment plug-in