Issue Details (XML | Word | Printable)

Key: SJC-74
Type: New Feature New Feature
Status: Resolved Resolved
Resolution: Deferred
Priority: Minor Minor
Assignee: Chris Beams
Reporter: Chris Beams
Votes: 1
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Spring JavaConfig

Support @Bean method parameter annotations for PropertyPlaceholderConfigurer-style injection

Created: 07/Mar/08 11:20 AM   Updated: 05/Sep/08 08:49 PM   Resolved: 05/Sep/08 08:49 PM
Component/s: Public API
Affects Version/s: None
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments: 1. Zip Archive mylyn-context.zip (38 kB)

Issue Links:
Related
 
Supersede
 


 Description  « Hide
[Entered on Alef's behalf by Chris Beams, per email conversations]

I don't know what the current support for PropertyPlaceholderConfigurer-like stuff is, but I was thinking that we should definitely have somethin glike this. What about the following:

@Configuration public class Config {

public DataSource dataSource(@PlaceholderParam("database.pwd") String pwd) {
return new DummyDataSource(pwd);
  }
}

In other words, property-placeholding support similar to @RequestParam and @XPathParam in Spring @MVC and Spring @WS respectively.

Chris Beams added a comment - 07/Mar/08 11:25 AM
Alef,

There is actually new support in the forthcoming M3 for @ResourceBundles and @ExternalValue, which goes a little something like this:

@Configuration
@ResourceBundles("classpath:/com/myco/datasource")
class MyConfig {
@Bean
public DataSource dataSource() {
return new FooDataSource(url(), username(), password());
}

@ExternalValue("datasource.url")
abstract String url();

@ExternalValue("datasource.username")
abstract String username();

@ExternalValue("datasource.password")
abstract String password();
}

So then: there must be present a com/myco/datasource.properties file in the classpath, with datasource.url, etc name/value pairs.

With that said, I really like your idea, and it's somewhat related to issues SJC-50, SJC-51 and SJC-16. I've added this New Feature request so it can be properly considered.

Colin Yates added a comment - 18/Mar/08 10:25 AM
I like the annotation living on the parameter as the example given requires needless methods being created (the url, username and password methods).

I understand that the implementation of those methods could provide a default value, but as it stands they are just extra noise. OTOH you could argue (from a relatively academic POV) that where username comes from has nothing to do with consumers of username, so having those extra methods is arguably cleaner.

Why not both?

Chris Beams added a comment - 13/Apr/08 09:26 AM
@ExternalValue is now supported as a parameter annotation to @Configuration class constructors or @Bean methods.

See latest nightly build documentation for details:

http://static.springframework.org/spring-javaconfig/site/spring-javaconfig/reference/html/new-and-noteworthy.html#new-and-noteworthy-1.0.0.m4

Chris Beams added a comment - 13/Apr/08 02:15 PM
Attaching final task context

Chris Beams added a comment - 12/Jun/08 08:55 AM - edited
This functionality has been removed as part of the refactoring effort in SJC-98. It may or may not be re-implemented. Please vote and comment if this is a feature you'd like to see.

Chris Beams added a comment - 05/Sep/08 08:49 PM
In alignment with SJC-50 and SJC-51, deferred for now. There are fundamental flaws with providing arguments to @Bean methods, in that it makes them un-callable by other higher-level @Bean methods.

With regard to PropertyPlacholder-like support, see @PropertiesValueSource and @ExternalValue.