我正在尝试使用Gradle多项目构建使用共享包设置Micronaut(1.1.0.BUILD-SNAPSHOT
)项目,以便可以将通用逻辑放在一个地方。
在为库创建属性文件时遇到了问题。我在application.yml
中放置了一些特定于库的属性,但是看起来它们没有被推送到应用程序层:
lib / src / main / java / 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:
testProperty: test
app / src / main / java / app / AppController.java
@Controller("/app")
public class AppController {
@Inject
private CommonSingleton commonSingleton;
@Get(produces = MediaType.TEXT_PLAIN)
public String index() {
return "Hello World";
}
}
错误是:
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
完整示例见on Github。
答案 0 :(得分:0)
当前,它仅设计用于读取单个from fuzzywuzzy import fuzz
。如果要从fuzz.ratio('Lord of the Rings', 'The Lord of the Rings')
中删除文件,将从application.yml
中读取该文件。您可以提出问题,以使我们知道这是您想要的。 https://github.com/micronaut-projects/micronaut-core/issues