Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why cannot I obtain the placeholder from the configuration file #33626

Open
robben009 opened this issue Nov 12, 2024 · 5 comments
Open

Why cannot I obtain the placeholder from the configuration file #33626

robben009 opened this issue Nov 12, 2024 · 5 comments

Comments

@robben009
Copy link

robben009 commented Nov 12, 2024

  <dependency>
      <groupId>org.apache.shardingsphere</groupId>
      <artifactId>shardingsphere-jdbc</artifactId>
     <version>5.5.0</version>
</dependency>

l hava a application.yml config file. file have a config content is

dbPwd: 1234556

spring:
  datasource:
    driver-class-name: org.apache.shardingsphere.driver.ShardingSphereDriver
    url: jdbc:shardingsphere:classpath:sharding-dev.yml?placeholder-type=system_props

and l hava a sharding-dev.yml file,config content is

dataSources:
  ds_0:
    dataSourceClassName: com.zaxxer.hikari.HikariDataSource
    driverClassName: com.mysql.cj.jdbc.Driver
    jdbcUrl: ***
    username: ***
    password: $${dbPwd::}

why $${dbPwd::} is not effect?

@linghengqian
Copy link
Member

Obviously, it's because you haven't set the system property of dbPwd. The content in application.yml will not be automatically set as system properties.

@robben009
Copy link
Author

Obviously, it's because you haven't set the system property of dbPwd. The content in application.yml will not be automatically set as system properties.

Is there support for getting properties from application.properties instead of placeholders

@linghengqian
Copy link
Member

  • In this case, you need to actively implement the spi of the shardingsphere jdbc driver to read the application.yml on the classpath.

  • You cannot put the spi implementation class of shardingsphere into the life cycle of spring context, because shardingsphere jdbc datasource allows multiple instances, and the spi implementation class is easily created and used by internal classes. For spring boot, you can directly regard spring context as a single instance such as jaas.

  • I would say you can feel free to consult the spring boot documentation to understand why the spring context's internal map itself is not suitable for storing metadata.

@linghengqian
Copy link
Member

By the way, you can create a spring bean of applicationrunner to initialize a bunch of system properties.

@robben009
Copy link
Author

ok l get, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants