DEV Community

Maxime Guilbert
Maxime Guilbert

Posted on • Updated on

Generate random values in your properties - Spring Boot

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!

Top comments (3)

bzani profile image
Bruno Zani

Very interesting tip, thanks for sharing.

mnmpeterson profile image

I couldn't get the range examples to work . . . even after adding the missing left parentheses.

mxglt profile image
Maxime Guilbert

Did you add it in your applilcationn.yaml file?