DEV Community

loading...

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 application.properties or in your application.yaml, you can use the next functions to generate random values.

# Random int
a=${random.int}

# Random int with a maximum value
b=${random.int(1000)}

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

# Random long with a maximum value
d=${random.long(100000000000000000)}

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

# Random 32 bytes value
f=${random.value}

# Random UUID
g=${random.uuid}
Enter fullscreen mode Exit fullscreen mode

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

h=test-${random.int}-value
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)

pic
Editor guide
Collapse
bzani profile image
Bruno Zani

Very interesting tip, thanks for sharing.