任何人都可以解决这个问题 我得到以下在eclipse上运行的错误
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personController': Injection of autowired dependencies failed; nested
exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.spring.service.CustomerService
com.spring.controller.PersonController.customerService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'customerService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.spring.repository.CustomerRepository com.spring.service.CustomerServiceImpl.customerRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.spring.repository.CustomerRepository] 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)}
我有以下
1.PersonController (class)
2.Person (class)
3.CustomerService (interface)
4.CustomerServiceImpl (class)
5.CustomerRepository (interface)
package com.spring.controller
in PersonController (class)
=====================
@Autowired
private CustomerService customerService;
@RequestMapping(value = "/person", method = RequestMethod.GET)
public String getPersonList(ModelMap model) {
model.addAttribute("personList", customerService.findAlls());
return "output";
}
package com.spring.service
in CustomerService (interface)
==================
public List<Person> findAlls();
package com.spring.service
in CustomerServiceImpl
=====================
@Service("customerService")
public class CustomerServiceImpl implements CustomerService {
@Autowired
private CustomerRepository customerRepository;
public List<Person> findAlls() {
List<Person> usersList = customerRepository.findAll();
return null;
}
}
package com.spring.repository
in CustomerRepository
===========================
@Repository("customerRepository")
public interface CustomerRepository extends MongoRepository<Person, String> {
public List<Person> findAll();
}
感谢和问候