0

I have class like this

public class Cat extends Animal{

   public Cat() {
     super(configValue)
   }
}

I need to pass configValue from application.yaml but I can't add the @Value({config.value}) annotation to the Cat constructor because there is a code which I can't control which calls no arg constructor of the Cat and does new Cat()

How can I pass configValue to the Animal

java_doctor_101
  • 3,287
  • 4
  • 46
  • 78
  • You can't. Rethink your design. Please share your higher level goal. – Sotirios Delimanolis Jan 27 '22 at 16:09
  • Try to check if this topic can help you https://stackoverflow.com/questions/30528255/how-to-access-a-value-defined-in-the-application-properties-file-in-spring-boot?page=1&tab=active#tab-top – fabio19933 Jan 27 '22 at 16:16
  • fabio19933 thx but I have tried all the approaches mentioned in that thread.. the issue is that constructor is called before value annotation is processed and the only way to reverse the order is by passing value in constructor param which is not possible for me Sotirios.. are you sure there is no way? My design limit me because of the third party library we are using which only accept an instance with no arg constructor.. the library uses following reflective call which will only work with a no arg constructor of my Cat object Cat.getClass().getConstructor().newInstance(); – java_doctor_101 Jan 27 '22 at 18:13

0 Answers0