Spring Framework
  1. Spring Framework
  2. SPR-9505

Environment (if provided by an ApplicationContext) should be able to convert String->Resource

    Details

    • Type: New Feature New Feature
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.1.1
    • Fix Version/s: 4.x Backlog
    • Component/s: Core:Environment
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      Environment (if provided by an ApplicationContext) should be able to convert String->Resource. Example, today I have to inject a ResourceLoader explicitly:

      public class ExampleConfiguration {
      	
      	@Autowired
      	private Environment environment;
      	
      	@Autowired
      	private ResourceLoader resourceLoader;
      	
      	@PostConstruct
      	protected void initialize() {
      		ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
      		populator.addScript(resourceLoader.getResource(environment.getProperty("batch.schema.script")));
      		DatabasePopulatorUtils.execute(populator , dataSource());
      	}
      ...
      

      It would be better to be able to do this

      public class ExampleConfiguration {
      	
      	@Autowired
      	private Environment environment;
      	
      	@PostConstruct
      	protected void initialize() {
      		ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
      		populator.addScript(environment.getProperty("batch.schema.script", Resource.class));
      		DatabasePopulatorUtils.execute(populator , dataSource());
      	}
      ...
      

        Activity

        Hide
        Chris Beams added a comment -

        Agreed. Thanks, Dave.

        Show
        Chris Beams added a comment - Agreed. Thanks, Dave.

          People

          • Assignee:
            Unassigned
            Reporter:
            Dave Syer
            Last updater:
            Chris Beams
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Days since last comment:
              1 year, 45 weeks ago