0

I have one java class:

public static class ErrorMessagesLocalized {
    @Value("${INVALID_ARGUMENT}")
    private String value;
    ...
}

I have 2 property files which contains same key(INVALID_ARGUMENT).

Does spring allow to create 2 instances of ErrorMessagesLocalized (instance per file) ?

gstackoverflow
  • 36,709
  • 117
  • 359
  • 710

1 Answers1

0

Spring picks up the value from the last property file it reads. If you want to read both the files and decide on runtime from where you need to read the value, follow this post : Reading multiple properties having same keys in spring

Community
  • 1
  • 1
Durlabh Sharma
  • 397
  • 2
  • 14
  • I am aware about this. My question differs – gstackoverflow Apr 19 '17 at 13:22
  • My Bad. Yes, you can create multiple instances of any class in Spring. Defining it multiple times in app-context creates multiple singleton instances of same class. You'll, then, have to instantiate the desired class according to the qualifier specified in app-context config. – Durlabh Sharma Apr 20 '17 at 05:54
  • it looks closer. But I don't know how to have several contexts. Actually I use java config. Can you provide details of your solution? – gstackoverflow Apr 20 '17 at 07:50
  • Why exactly do you need multiple instances of class for every property file when it can be done with a single instance of class using multiple property files? – Durlabh Sharma Apr 20 '17 at 10:06
  • it something like localization but not localization) – gstackoverflow Apr 20 '17 at 11:18