Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-9473

Resolve nested ${..} placeholders via PropertyResolver/Environment

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 3.1 GA
    • Fix Version/s: 3.1.2, 3.2 M2
    • Component/s: Core:Environment
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              cbeams Chris Beams
              Reporter:
              andre.berenguel André Berenguel
              Last updater:
              Spring Issues
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                2 years, 40 weeks, 2 days ago