2

I created an Indexable annotation with an indexName attribute, this annotation has to be placed on top of a class, i want to add a prefix to the indexName that i define in application.yml file

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 "";

}
Aymen Kanzari
  • 1,765
  • 7
  • 41
  • 73
  • Have you tried this https://stackoverflow.com/a/47178928/4235401 ? –  May 28 '18 at 09:47
  • @ConfigurationProperties th get the values that are in the application file inside the class, but i want to get it above the class – Aymen Kanzari May 28 '18 at 09:53
  • Take a look at https://stackoverflow.com/a/14276270/5098338. I am sure that this will help. The solution may differ and depends on jdk version. With the help of this tweak you will be able to change the annotation value in runtime. – jahra May 28 '18 at 10:00
  • thnx @jahra ^^ , I found a problem with the version of jdk, but I found the solution in this [article](http://www.baeldung.com/java-reflection-change-annotation-params) – Aymen Kanzari May 28 '18 at 11:20

1 Answers1

2

Use the @Value("${yaml.path.to.value}") annotation on the field you want to set the value. For instance for the yaml.path.to.value :


yaml:
  path:
    to:
     value: someValue

Be careful with the spaces when using yml.

Ivan Aranibar
  • 2,226
  • 2
  • 18
  • 21