对于这个演示:
event-starter
模块中定义了一个 Bean 作为 Spring Boot Starter,我想在我的应用程序模块中使用它:application
。据我所知,它在 GreeterAutoConfiguration
文件和 resources/META-INF/spring.factories
build.gradle
模块中的
application
文件将
event-starter
作为依赖项引入,如下所示:
implementation project(':event-starter')
io.spring.dependency-management
和
org.springframework.boot:spring-boot-configuration-processor
注释处理器。
运行应用程序时,Spring IoC 容器似乎无法发现我从启动器模块中拉入的 Bean,我不知道为什么:
Field greeter in com.example.app.StarterApplication required a bean of type 'com.example.starter.Greeter' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.example.starter.Greeter' in your configuration.
我大致使用这两个教程 [
任何帮助识别缺失/错误的信息将不胜感激!
import org.springframework.stereotype.Service;
@Service
public class Greeter {
public String greet() {
return "hello";
}
}
这应该可以解决你的错误