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

Can't resolve placeholder in Spring Boot YAML configuration #1011

Closed
errordaiwa opened this issue Jul 15, 2018 · 4 comments · Fixed by #1020
Closed

Can't resolve placeholder in Spring Boot YAML configuration #1011

errordaiwa opened this issue Jul 15, 2018 · 4 comments · Fixed by #1020
Assignees

Comments

@errordaiwa
Copy link
Contributor

For English only, other languages we will close it directly.

Please answer these questions before submitting your issue. Thanks!

Which version of Sharding-Sphere do you using?

2.0.3

Expected behavior

resolve placeholder

Actual behavior

treat placeholder as raw string

Steps to reproduce the behavior

  • use placeholder in configuration yaml
sharding:
  jdbc:
    datasource:
      names: ds
      ds: 
        url: ${KEY_IN_OS_ENV}
  • start application
  • get "malfrom url" exception because jdbc get "${KEY_IN_OS_ENV}" for url connection

Reason analyze

Sharding JDBC get configuration from spring boot yaml files by io.shardingjdbc.spring.boot.SpringBootConfiguration. The code to get datasource configuration is blow

private void setDataSourceMap(final Environment environment) {
        RelaxedPropertyResolver propertyResolver = new RelaxedPropertyResolver(environment, "sharding.jdbc.datasource.");
        String dataSources = propertyResolver.getProperty("names");
        for (String each : dataSources.split(",")) {
            try {
                Map<String, Object> dataSourceProps = propertyResolver.getSubProperties(each + ".");
                Preconditions.checkState(!dataSourceProps.isEmpty(), "Wrong datasource properties!");
                DataSource dataSource = DataSourceUtil.getDataSource(dataSourceProps.get("type").toString(), dataSourceProps);
                dataSourceMap.put(each, dataSource);
            } catch (final ReflectiveOperationException ex) {
                throw new ShardingJdbcException("Can't find datasource type!", ex);
            }
        }
    }

getProperty(String) can recognize placeholder and parse it. But RelaxedPropertyResolver.getSubProperties(String) can't. So all the placeholder has been resolved as raw string and pass to Sharding JDBC framework.

@errordaiwa
Copy link
Contributor Author

@terrymanu if it is confirmed to be a bug, I can contribute my workaround with pull request.

@terrymanu
Copy link
Member

I think this it a bug, but we still need more investigate, because we don't have this test case.

If you want contribute a pull request, we really thank you. Please do it, thank you.

@errordaiwa
Copy link
Contributor Author

@terrymanu I fix the issue only under spring boot v1 because PropertyUtil seems to work properly under v2.

@terrymanu terrymanu changed the title Can't resolve placeholder in spring boot configuration yaml Can't resolve placeholder in Spring Boot YAML configuration Aug 8, 2018
@terrymanu
Copy link
Member

fixed at 3.0.0.M1

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

Successfully merging a pull request may close this issue.

2 participants