1
@Pattern(regexp = "{A-Za-z0-9}*")
private String name;

Above regex, I want to read from the property file

3
  • 2
    "${your.config.key:-default value}". Have you tried that and it does not work or haven't you tried it and don't know about it? Commented Jan 3, 2020 at 16:33
  • @knittl I tried several times without success, IntelliJ put a red highlight after '${' with the message "Number expected" Commented May 10, 2022 at 13:28
  • @DonFabiolas but what does the Java compiler say? Commented May 10, 2022 at 16:27

1 Answer 1

1

This is possible from Spring 3.0.1 afterwords. You can do it like a regular property value binding. Inside your application.yml

my:
  regex:
    charOrNumber: '{A-Za-z0-9}*'

And then in your Java class:

@Pattern(regexp = "${my.regex.charOrNumber}")
Sign up to request clarification or add additional context in comments.

2 Comments

I tried several times without success, IntelliJ put a red highlight after '${' with the message "Number expected"
@DonFabiolas this should help stackoverflow.com/questions/69524543/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.