简体   繁体   English

春季4中没有任何类型的合格Bean

[英]No qualifying bean of type in Spring 4

Currently I'm facing an issue in Autowire configuration between controller and the service layer. 目前,我在控制器和服务层之间的Autowire配置中遇到问题。

Log 日志记录

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.ults.hrms.service.EmployeeService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

Controller 控制者

@Controller
@RequestMapping("/")
public class AppController extends ConvertReqDataToJSON {

    final static Logger logger = Logger.getLogger(AppController.class);

    /* creating bean definition in Spring container(DI) */

    @Autowired
    EmployeeService employeService;

    @RequestMapping(value = { "/listuser" }, method = RequestMethod.GET)
    public @ResponseBody List<Employe> listUsers() throws Exception {

        return employeService.findAllUsers();
    }
}

Service 服务

@Service
public class EmployeeService extends GenericDaoImpl<Employe>{

    public List<Employe> findAllUsers() throws Exception {
        return findAllUsers();
    }
}
GenericDao

@SuppressWarnings("unchecked")
@Transactional
@Repository
public abstract class GenericDaoImpl<T> implements IGenericDao<T> {

    protected Class<T> entityClass;

    @Autowired
    private SessionFactory sessionFactory;

public T findAll() throws Exception{
        Criteria criteria =sessionFactory.getCurrentSession().createCriteria(getEntityClass()).addOrder(Order.asc("firstName"));
        criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        return (T) criteria.list();
    }
}

Autowiring doesnt work for some reason... " No qualifying bean of type com.ults.hrms.service.EmployeeService . 由于某些原因,自动装配不起作用...“ No qualifying bean of type com.ults.hrms.service.EmployeeService

I've tried with different combinations of @Component and @Transactional too. 我也尝试了@Component@Transactional不同组合。

Sorry for a lot of code, but I don't know what can cause that error anymore. 抱歉,有很多代码,但是我不知道是什么导致了该错误。

The root cause of No qualifying bean of type [com.ults.hrms.service.EmployeeService] is that the autowired property name is not correct.. No qualifying bean of type [com.ults.hrms.service.EmployeeService]的根本原因是自动装配的属性名称不正确。

change 更改

@Autowired
EmployeeService employeService;

to

@Autowired
EmployeeService employeeService ;

You can do like this 你可以这样

@Service("employeService")
public class EmployeeService extends GenericDaoImpl<Employe>{

    public List<Employe> findAllUsers() throws Exception {
        return findAllUsers();
    }
}

@Service***("employeService")*** this allows you to choose the name you are going to use while autowiring @Service ***(“ employeService”)***这使您可以选择自动装配时要使用的名称

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Boot JPA-没有合格的bean类型 - Spring Boot JPA - No qualifying bean of type 没有合格的bean类型(Spring Data) - No qualifying bean of type available (Spring Data) Spring Data Redis NoSuchBeanDefinitionException:没有类型的限定bean - Spring Data Redis NoSuchBeanDefinitionException: No qualifying bean of type Spring Framework没有类型为MessageSourceAccessor JAVA的合格Bean - Spring Framework No qualifying bean of type MessageSourceAccessor JAVA 春季安全性没有类型为AuthenticationSuccessHandler和AuthenticationFalureHandler的合格Bean - spring security No qualifying bean of type AuthenticationSuccessHandler and AuthenticationFalureHandler Spring启动测试“没有可用的限定bean” - Spring boot test “No qualifying bean of type available” Spring MVC项目上没有任何类型的合格Bean - No qualifying bean of type on spring mvc project Spring Boot中的JPA存储库“没有类型的限定bean” - “No qualifying bean of type” for JPA repository in Spring Boot 未找到Spring @Autowired bean,找不到类型[...]的限定bean - Spring @Autowired bean not found, No qualifying bean of type […] found Spring Framework 错误创建具有名称的 bean 并且没有符合条件的 bean 类型 - Spring Framework Error creating bean with name and No qualifying bean of type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM