简体   繁体   English

Micronaut属性注入不适用于Gradle多项目构建

[英]Micronaut property injection does not work with Gradle multi-project build

I am trying to setup Micronaut ( 1.1.0.BUILD-SNAPSHOT ) project with a shared package using Gradle multi-project build so I can put the common logic in one place. 我正在尝试使用Gradle多项目构建使用共享包设置Micronaut( 1.1.0.BUILD-SNAPSHOT )项目,以便可以将通用逻辑放在一个地方。

I encountered the problem during the creation of the property file for the library. 在为库创建属性文件时遇到了问题。 I put some library specific properties in application.yml but looks like they are not pushed forward to the application layer: 我在application.yml一些库特定的属性,但是看起来它们没有被推送到应用程序层:

lib/src/main/java/lib/CommonSingeton.java LIB / SRC /主/爪哇/ LIB / CommonSingeton.java

@Singleton
public class CommonSingleton {

  public CommonSingleton(
    @Value("${lib.testProperty}") String value
  ) {
    System.out.println(value);
  }
}

lib/src/main/resources/application.yml LIB / src目录/主/资源/ application.yml

lib:
  testProperty: test

app/src/main/java/app/AppController.java 应用程序/ SRC /主/ JAVA /应用程序/ AppController.java

@Controller("/app")
public class AppController {

  @Inject
  private CommonSingleton commonSingleton;

  @Get(produces = MediaType.TEXT_PLAIN)
  public String index() {
    return "Hello World";
  }
}

The error is: 错误是:

Unexpected error occurred: Failed to inject value for parameter [value] of class: lib.CommonSingleton

Message: Error resolving property value [${lib.testProperty}]. Property doesn't exist
Path Taken: AppController.commonSingleton --> new CommonSingleton([String value])
io.micronaut.context.exceptions.DependencyInjectionException: Failed to inject value for parameter [value] of class: lib.CommonSingleton

The complete example is available on Github . 完整的示例在Github上可用。

Currently it is designed to just read a single application.yml . 目前,它仅设计用于读取单个application.yml If you were to remove the file from app , it would be read from lib . 如果要从app删除文件,则将从lib读取该文件。 You can file an issue to make us aware this is something you want. 您可以提出问题,以使我们知道这是您想要的。 https://github.com/micronaut-projects/micronaut-core/issues https://github.com/micronaut-projects/micronaut-core/issues

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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