2 java spring intellij-idea spring-boot
我也看到了有关付费版本的问题,但找不到解决方案。IDEA CE 抱怨缺少应该定义的 bean。
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.
Run Code Online (Sandbox Code Playgroud)
但在我的控制器中,我确实有它:
@Autowired
private KitchenService service;
Run Code Online (Sandbox Code Playgroud)
我发现的大多数解决方案都不清楚,唯一明确的解决方案是用 3 个注释来注释起点类@SpringBootApplication,但没有什么区别。
怎么解决呢?
首先,Intellij IDEA 不是免费的 IDE。对于大规模开发和框架支持,您需要购买Intellij IDEA Ultimate Edition才能获得所有支持。
在免费版本中,他们不提供 Spring 支持。
免费 IDE 推荐:最好的免费 IDE 是Spring Tools Suite。Pivotal 团队专门设计了 Eclipse IDE 来支持 Spring 框架,它比任何其他 IDE 都要好得多。
而且Pivotal也推荐使用这个IDE。
没有创建bean的原因KitchenService如下:
@Service上缺少任一注释KitchenService。
或者您错过了将包添加到存在的@ComponentScan位置KitchenService。
因此, KitchenService bean 丢失了,当您自动装配它时,Spring 无法找到该 bean。
请根据这些原因来验证问题。