Uploaded image for project: '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
    • Status: Resolved
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: 3.1.1
    • Fix Version/s: None
    • 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
        cbeams Chris Beams added a comment -

        Agreed. Thanks, Dave.

        Show
        cbeams Chris Beams added a comment - Agreed. Thanks, Dave.
        Hide
        juergen.hoeller Juergen Hoeller added a comment -

        Actually, Environment based property coercion isn't really meant to provide comprehensive conversion capabilities to begin with, in particular not when having to rely on external facilities. Direct ResourceLoader usage doesn't seem so bad here.

        Juergen

        Show
        juergen.hoeller Juergen Hoeller added a comment - Actually, Environment based property coercion isn't really meant to provide comprehensive conversion capabilities to begin with, in particular not when having to rely on external facilities. Direct ResourceLoader usage doesn't seem so bad here. Juergen

          People

          • Assignee:
            juergen.hoeller Juergen Hoeller
            Reporter:
            david_syer Dave Syer
            Last updater:
            Juergen Hoeller
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              50 weeks, 1 day ago