Can we have SpEL in configuration file
Let me give one use case as an example
spring.datasource.url=jdbc:mysql://localhost:3306/spring
spring.datasource.username=root
spring.datasource.password=<encrypted value>
In this example, my properties define an encrypted password. To decrypt it, i need to go thru the cumbersome of having to create manually a DataSource bean. If spring allows SpEL in configuration, such cumbersome activity can be bypass , by doing something like
spring.datasource.url=jdbc:mysql://localhost:3306/spring
spring.datasource.username=root
spring.datasource.password=#{T(xx.com.Decryptor).decryptPassword('<encrypted value>')}}
Now no need to go thru the hassle of programmatically creating a datasource bean. I know someone would suggest a third party library (such as jasypt) to deal with my aforementioned scenario. But the above is just only an example. It might not be related to decrypting an encrypted value.
Comment From: wilkinsona
Thanks for the suggestion but, as with https://github.com/spring-projects/spring-boot/issues/7059, we think that it would add too much complexity to support SpEL in configuration files.
Comment From: hannah23280
@wilkinsona Hi noted. Thanks for the response. I noted that properties value can have value randomly generated like this test.random.number = ${random.int}
Can provide some hint, how is this ${random..} being implemented in spring boot ? cos i was thinking of implementing something similar to this random to resolve my aforementioned issue.
Comment From: hannah23280
@wilkinsona Hi noted. Thanks for the response. I noted that properties value can have value randomly generated like this test.random.number = ${random.int}
Can provide some hint, how is this ${random..} being implemented in spring boot ? cos i was thinking of implementing something similar to this random to resolve my aforementioned issue.
I think its ok. I found it. There is a class called RandomValuePropertySource which extends PropertySource. I will study that