【发布时间】:2021-08-05 19:03:06
【问题描述】:
我的应用 yaml 是这样的:
my:
config:
currentValue: 500
我的代码尝试像这样使用这个值:
@Singleton
public class MyClass {
@Value("${my.config.current-value}")
private final int myProperty;
public MyClass(int myProperty) {
this.myProperty = myProperty;
}
}
但它没有启动它,因为当我运行应用程序时出现错误:
{"message":"Internal Server Error: Failed to inject value for parameter [myProperty] of class: com.foo.bar.MyClass Message: No bean of type [java.lang.String] exists. Make sure the bean is not disabled by bean requirements
我错过了什么?
【问题讨论】:
-
为什么要在字段上既要
@Value,又要在构造函数中给字段赋值呢? -
我不知道!我做这一切都错了。谢谢!
标签: java dependency-injection javabeans micronaut