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

Resolve nested ${..} placeholders via PropertyResolver/Environment [SPR-9473] #14108

Closed
spring-projects-issues opened this issue Jun 5, 2012 · 1 comment

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Jun 5, 2012

André Berenguel opened SPR-9473 and commented

The following code does not resolve the property ${database.url} correctly.

@Configuration
@PropertySource("classpath:/myapp.properties")
public class ApplicationConfig {

    @Autowired
    private Environment env;

    ...

    @Bean(destroyMethod = "close")
    public DataSource dataSource() {

        ...
        dataSource.setJdbcUrl(env.getProperty("database.url"));
        ...
    }

When the file myapp.properties is like

database.host=localhost
database.port=3306
database.base=mybase

database.url=jdbc:mysql://${database.host}:${database.port}/${database.base}?autoReconnect=true

The property is being resolved as it is declared: jdbc:mysql://${database.host}:${database.port}/${database.base}?autoReconnect=true
I expected it was resolved as jdbc:mysql://localhost:3306/mybase?autoReconnect=true


Affects: 3.1 GA

Issue Links:

  • #14203 Allow PropertyResolver implementations to ignore unresolvable ${placeholders} ("is depended on by")
@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 6, 2012

Chris Beams commented

commit 2ec7834124dfa32d7b90afbb23805433a4567bf5
Author: Chris Beams <cbeams@vmware.com>
Commit: Chris Beams <cbeams@vmware.com>

    Resolve nested placeholders via PropertyResolver
    
    Prior to this change, PropertySourcesPropertyResolver (and therefore
    all AbstractEnvironment) implementations failed to resolve nested
    placeholders as in the following example:
    
        p1=v1
        p2=v2
        p3=${v1}:{$v2}
    
    Calls to PropertySource#getProperty for keys 'p1' and 'v1' would
    successfully return their respective values, but for 'p3' the return
    value would be the unresolved placeholders. This behavior is
    inconsistent with that of PropertyPlaceholderConfigurer.
    
    PropertySourcesPropertyResolver #getProperty variants now resolve any
    nested placeholders recursively, throwing IllegalArgumentException for
    any unresolvable placeholders (as is the default behavior for
    PropertyPlaceholderConfigurer). See SPR-9569 for an enhancement that
    will intoduce an 'ignoreUnresolvablePlaceholders' switch to make this
    behavior configurable.
    
    This commit also improves error output in
    PropertyPlaceholderHelper#parseStringValue by including the original
    string in which an unresolvable placeholder was found.
    
    Issue: SPR-9473, SPR-9569

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

Successfully merging a pull request may close this issue.

None yet
1 participant