Could not autowire field in spring. why?

后端 未结 8 1807
长情又很酷
长情又很酷 2020-12-08 20:09

I keep getting this error, and can\'t figure out why.. yes I know there many people had similar issues, but reading the answers they got, does not solve my problem.

8条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-08 20:47

    In spring servlet .xml :

    
    

    (I assumed that the service impl is in the same package as the service interface "net.service")

    I think you have to add the package net.service (or all of net) to the component scan. Currently spring only searches in net.controller for components and as your service impl is in net.service, it will not be instantiated by spring.

提交回复
热议问题