2015-12-21 2 views
0

Я просто не могу понять это!Ошибка при создании bean-injection автоуведомленных зависимостей

Я получаю эту ошибку

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.packt.webstore.service.CustomerService com.packt.webstore.controller.CustomerController.customerService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.packt.webstore.domain.repository.CustomerRepository com.packt.webstore.service.impl.CustomerServiceImpl.customerRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.packt.webstore.domain.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)} 
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) 
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703) 
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) 
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) 
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658) 
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624) 
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672) 
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543) 
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484) 
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) 
at javax.servlet.GenericServlet.init(GenericServlet.java:158) 
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284) 
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1197) 
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:864) 
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:134) 
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) 
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) 
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) 
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) 
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957) 
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) 
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423) 
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079) 
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620) 
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) 
at java.lang.Thread.run(Unknown Source) 

Вот мой домен клиента

public class Customer { 
private String customerId; 
private String name; 
private String address; 
private int noOfOrderMade; 

public Customer(String customerId, String name){ 
    this.customerId = customerId; 
    this.name = name; 
} 

Это методы получения и установки в нем

Вот мой CustomerRepository

public interface CustomerRepository { 
List<Customer> getAllCustomers(); 
} 

Вот мой InMemoryCustomerRepository с некоторыми данными

public class InMemoryCustomerRepository implements CustomerRepository { 
private List<Customer> listOfCustomers = new ArrayList <Customer>(); 

public InMemoryCustomerRepository(){ 
    Customer c1 = new Customer("1", "Ashesh Tuladhar"); 
    c1.setAddress("Ason"); 
    c1.setNoOfOrderMade(5); 

    Customer c2 = new Customer("2", "Ismaran Duwadi"); 
    c2.setAddress("Thankot"); 
    c2.setNoOfOrderMade(10); 

    Customer c3 = new Customer("3", "Siddhartha Bhatta"); 
    c3.setAddress("Hattisar"); 
    c3.setNoOfOrderMade(15); 

    listOfCustomers.add(c1); 
    listOfCustomers.add(c2); 
    listOfCustomers.add(c3); 
} 

public List<Customer> getAllCustomers(){ 
    return listOfCustomers; 
} 

Вот мой CustomerService

public interface CustomerService { 
    List<Customer> getAllCustomers(); 
} 

Вот мой CustomerServiceImpl

@Service 
public class CustomerServiceImpl implements CustomerService { 
@Autowired 
private CustomerRepository customerRepository; 
public List<Customer> getAllCustomers(){ 
    return customerRepository.getAllCustomers(); 
} 
} 

А вот CustomerController

@Controller 
public class CustomerController { 
    @Autowired 
    private CustomerService customerService; 

    @RequestMapping("/customer") 
    public String list(Model model){ 
     model.addAttribute("customers",customerService.getAllCustomers()); 
     return "customers"; 
    } 
    } 
+3

Опубликовать весь след стека. Вы отрезали все важные бит. – chrylis

ответ

1

Yo Интерфейс CustomerRepository должен либо расширять что-то вроде CRUDRepository, либо иметь аннотацию @RepositoryDefinition, иначе он не будет поднят весной.

+0

спасибо человеку глупо ошибку! – user3127109

Смежные вопросы

 Смежные вопросы