Java Spring启动-从application.yml访问值
我创建了一个带有indexName属性的可索引注释,该注释必须放在类的顶部,我想为我在application.yml文件中定义的indexName添加一个前缀Java Spring启动-从application.yml访问值,java,spring,spring-boot,Java,Spring,Spring Boot,我创建了一个带有indexName属性的可索引注释,该注释必须放在类的顶部,我想为我在application.yml文件中定义的indexName添加一个前缀 application: elasticsearch: prefix: dev_ @Indexable(indexName = "${application.elasticsearch.prefix}address") public class Address implements Serializable { } @R
application:
elasticsearch:
prefix: dev_
@Indexable(indexName = "${application.elasticsearch.prefix}address")
public class Address implements Serializable {
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Indexable {
String indexName() default "";
}
在要设置值的字段上使用@Value(${yaml.path.to.Value}”)注释。例如,对于yaml.path.to.value:
yaml:
path:
to:
value: someValue
使用yml时要小心空格。您尝试过这个吗?@ConfigurationProperties获取类内应用程序文件中的值,但我想获取类上方的值。请查看。我相信这会有所帮助。解决方案可能有所不同,并且取决于jdk版本。在这个调整的帮助下,您将能够在运行时更改注释值。thnx@jahra^^,我发现jdk版本存在问题,但我在这里找到了解决方案