[xxxx.xxxx.xxxx] 类型的 bean 不存在。确保该 bean 未被 bean 要求禁用 Micronaut 消息传递应用程序

No bean of type [xxxx.xxxx.xxxx] exists. Make sure the bean is not disabled by bean requirements Micronaut messaging application

我有以下项目结构

主项目DEMO依赖于Gradle项目SERVICE实现了[=42]的接口=]PORT 项目.

演示 build.gradle

dependencies {
    implementation project(':port')
    runtime project(':service')
} 

服务build.gradle

dependencies {
    implementation project(':port')

    implementation("javax.annotation:javax.annotation-api:1.3.2")
    compile "io.micronaut:micronaut-inject:2.4.0"
    annotationProcessor "io.micronaut:micronaut-inject-java:2.4.0"
}

服务class实现IStartUpPort

@Singleton
public class StartUpService implements IStartUpPort {
    @Override
    public void toUpperCase() {
        System.out.println("Something happened");
    }
}

端口build.gradle

dependencies {
    implementation("javax.annotation:javax.annotation-api:1.3.2")
    compile "io.micronaut:micronaut-inject:2.4.0"
    annotationProcessor "io.micronaut:micronaut-inject-java:2.4.0"
}

端口接口

public interface IStartUpPort {
    void toUpperCase();
}

在主项目中,我在服务项目上做DI,遇到异常

@Singleton
public class StartUp implements ApplicationEventListener<StartupEvent> {
    private final IStartUpPort iStartUpPort;

    public StartUp(IStartUpPort iStartUpPort) {
        this.iStartUpPort = iStartUpPort;
    }

    @Override
    public void onApplicationEvent(StartupEvent event) {
        iStartUpPort.toUpperCase();
    }
}

异常

Message: No bean of type [fete.bird.IStartUpPort] exists. Make sure the bean is not disabled by bean requirements (enable trace logging for 'io.micronaut.context.condition' to check) and if the bean is enabled then ensure the class is declared a bean and annotation processing is enabled (for Java and Kotlin the 'micronaut-inject-java' dependency should be configured as an annotation processor).
Path Taken: new StartUp([IStartUpPort iStartUpPort])
    at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:1034)
    at com.example.$StartUpDefinition.build(Unknown Source)
    at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1943)
    at io.micronaut.context.DefaultBeanContext.addCandidateToList(DefaultBeanContext.java:3091)
    at io.micronaut.context.DefaultBeanContext.getBeanRegistrations(DefaultBeanContext.java:2968)
    at io.micronaut.context.DefaultBeanContext.getBeansOfType(DefaultBeanContext.java:762)
    at io.micronaut.context.DefaultBeanContext.publishEvent(DefaultBeanContext.java:1304)
    at io.micronaut.context.DefaultBeanContext.start(DefaultBeanContext.java:246)
    at io.micronaut.context.DefaultApplicationContext.start(DefaultApplicationContext.java:165)
    at io.micronaut.runtime.Micronaut.start(Micronaut.java:71)
    at io.micronaut.runtime.Micronaut.run(Micronaut.java:311)
    at io.micronaut.runtime.Micronaut.run(Micronaut.java:297)
    at com.example.Application.main(Application.java:8)
Caused by: io.micronaut.context.exceptions.NoSuchBeanException: No bean of type [fete.bird.IStartUpPort] exists. Make sure the bean is not disabled by bean requirements (enable trace logging for 'io.micronaut.context.condition' to check) and if the bean is enabled then ensure the class is declared a bean and annotation processing is enabled (for Java and Kotlin the 'micronaut-inject-java' dependency should be configured as an annotation processor).
    at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:2367)
    at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1261)
    at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:1012)
    ... 12 common frames omitted

这是一个 Micronuat 消息应用程序存储库,可以在此处找到 https://github.com/anandjaisy/MessengingMultiGradleProject

链接库中的当前代码已配置,如果正确构建和执行应用程序,问题中显示的错误将不会发生。

克隆存储库:

$ git clone git@github.com:anandjaisy/MessengingMultiGradleProject.git

构建服务:

$ cd MessengingMultiGradleProject
$ ./gradlew assemble

运行 服务:

$ java -jar build/libs/demo-0.1-all.jar 
 __  __ _                                  _   
|  \/  (_) ___ _ __ ___  _ __   __ _ _   _| |_ 
| |\/| | |/ __| '__/ _ \| '_ \ / _` | | | | __|
| |  | | | (__| | | (_) | | | | (_| | |_| | |_ 
|_|  |_|_|\___|_|  \___/|_| |_|\__,_|\__,_|\__|
  Micronaut (v2.4.0)

Something happened
13:33:55.037 [main] INFO  io.micronaut.runtime.Micronaut - Startup completed in 405ms. Server Running: 0 active message listeners.