简体   繁体   中英

Spring in IntelliJ IDEA Community Edition does not bind @Autowired

I have seen issues regarding the paid version as well, but couldn't find a solution. IDEA CE complains about a missing bean that should be defined.

The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'domain.service.KitchenService' in your configuration.

But in my controller, I do have it:

@Autowired
private KitchenService service;

The majority of the solutions I found weren't clear and the only clear one was to annotate the starting point class with the 3 annotations @SpringBootApplication has, but made no difference.

How to solve it?

First of all, Intellij IDEA is not a free IDE. For high-scale development and framework support, you need to buy Intellij IDEA Ultimate Edition to get all the support.

In free edition, they don't provide Spring support.

Recommendation for free IDE: The best free IDE is Spring Tools Suite. Pivotal team has specially designed the Eclipse IDE for Spring Framework support and it's far better than any other IDE.

And Pivotal also recommends to use this IDE.

The reason for why the KitchenService bean is not created are as follows:

  1. Either @Service annotation is missing on KitchenService .

  2. Or you have missed to add the package in @ComponentScan where KitchenService is present.

Therefore, KitchenService bean is missing and Spring is not able to find the bean when you are autowiring it.

Please verify the issue based on these reasons.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM