Skip to content

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

@spring-projects-issues

Description

@spring-projects-issues

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions