Spring @Autowired not working

后端 未结 7 2061
再見小時候
再見小時候 2021-02-08 12:35

I have some problems wth autowire annotation. My app looks like this:

Here is controller:

@Controller
public class MyController {
    @Autowired
    @Qua         


        
7条回答
  •  轮回少年
    2021-02-08 12:56

    There can be two reasons for this.

    1. When you have not annotated the injected object or say service with proper @Service/@Component/@Repository annotations.

    2. Once you have made sure of point 1 ,next check for whether the class package of your annotated service class is included in the class-path for your spring boot application in the main class.You can configure this using the following annotation.

    @SpringBootApplication(scanBasePackages = { "com.ie.efgh.somepackage","com.ie.abcd.someotherpackage" })

    Doing this you tell spring to look into the packages for the classes during class loading.

提交回复
热议问题