DEV Community


Generate random values in your properties - Spring Boot

adaendra profile image Maxime Guilbert ・1 min read

During some configurations with Kafka, I was at a point where I need a different group id for each instance of the same service.

So to set up it, I looked for how I can make prefixed group ids. And I found this.

In your or in your application.yaml, you can use the next functions to generate random values.

# Random int

# Random int with a maximum value

# Random int in a range
c=${[0, 9999])} 

# Random long with a maximum value

# Random long in a range
e=${random.long[10000, 999999999999999999])}

# Random 32 bytes value

# Random UUID
Enter fullscreen mode Exit fullscreen mode

And if you want, you can use them in the middle of a string.

Enter fullscreen mode Exit fullscreen mode

I hope it will help you!

Don't hesitate to give some feedback to help me to improve my writing skills. Thanks!

Discussion (1)

Editor guide
bzani profile image
Bruno Zani

Very interesting tip, thanks for sharing.