I want to externalize password for Java @DataSourceDefinition using OS system variable ${appuserpwd}. The below is my @DataSourceDefinition
@DataSourceDefinition(
name = "java:app/jdbc/mydb",
className = "com.mysql.cj.jdbc.MysqlConnectionPoolDataSource",
portNumber = 3306,
serverName = "localhost",
databaseName = "mydb",
user = "appuser",
password = "${appuserpwd}",
isolationLevel = Connection.TRANSACTION_READ_COMMITTED,
properties = {})
I am using Wildfly 18. In subsystem ee, I already turn on these properties:
Annotation Property Replacement: ON
JBoss Descriptor Property Replacement: ON
Spec Descriptor Property Replacement: ON
I always get an Exception error as below:
Caused by: java.sql.SQLException: Access denied for user 'appuser'@'localhost' (using password: YES)
It means Wildfly failed to translate ${appuserpwd} to the real password from OS system environment named appuserpwd.
I have tried ${env.appuserpwd} for @DataSourceDefinition password but I got the same message.
If I replace ${appuserpwd} by the appuser real password -> The app works OK, no issues.
Any helps? Thanks!