0

I have a one trouble (sorry for my English)

I read property from file by MessageSource ( org.springframework.context.MessageSource ):

public class SomeConstants {

   @Autowired
   private static MessageSource messageSource;
   private static final Locale locale = LocaleContextHolder.getLocale();

   public static final String NULL_MESSAGE = messageSource
       .getMessage( "propertyKey", new Object[]{}, locale );
}

Property file:

propertyKey = "Some message"

And I'm trying to pass NULL_MESSAGE, from SomeConstants class, to @NotNull annotation ( javax.validation.constraints.NotNull ) as message parameter:

@NotNull( message = NULL_MESSAGE )

And when try to compile this, get compilation error (I use Maven to build project):

[ERROR] NULL_MESSAGE value must be a constant expression

It is possible to set value by MessageSource during compilation or I should solve it by another way?

Vlad Mir
  • 1
  • 1
  • Possible duplicate of [How to supply value to an annotation from a Constant java](https://stackoverflow.com/questions/2065937/how-to-supply-value-to-an-annotation-from-a-constant-java) TL;DR: it's not possible – Alex Savitsky Jan 11 '18 at 16:22
  • I found some another solution here, thanks! – Vlad Mir Jan 15 '18 at 22:00

0 Answers0