[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Autowired dependencies and external configuration [SPR-4447] #9125

Closed
spring-projects-issues opened this issue Feb 11, 2008 · 6 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Bob Tiernay opened SPR-4447 and commented

Some great ideas about how to improve Spring's annotation based configuration is mentioned in the following article:

http://www.jroller.com/Solomon/entry/guice_and_spring_2_51

One of the stumbling blocks with a prodominantly annotation based configuration is the setup and injection of external configuration (the kind of stuff you want externalized in an XML file or a property file, such as connection information, file names, counts and Controller view names. Most of the time, those kinds of values are primitives). Typically, such configuration values come from properties files and are made available via variants of PropertyPlaceholderConfigurer. However, in such an environment this is difficult to achieve since Strings, Integers, etc are not considered component types (see http://jira.springframework.org/browse/SPR-3744).

One solution to this issue is what Solomon writes about:

An @Value annotation with property resolution... For example:

@Autowire public void setI(@Value("${i}") int i)

With a property file entry:

i=5

This seems very natural and seems to be the annotation configuration based version of Java Config's @ExternalValue (see http://www.thespringexperience.com/blog/rod_johnson/2007/11/spring_java_configuration_moving_ahead.html)

If this is a sensible approach, consider unifying the two annontations to be common.


Attachments:

3 votes, 7 watchers

@spring-projects-issues
Copy link
Collaborator Author

Bob Tiernay commented

Please see http://jira.springframework.org/browse/SJC-16 for Java Config's reasoning behind @ExternalValue

@spring-projects-issues
Copy link
Collaborator Author

Bob Tiernay commented

Also note the approach taken here to circumvent the current limitations:

http://www.find23.net/Site/Blog/Entries/2008/1/10_Spring_annotation_and_PropertyPlaceholderConfigurer.html

@spring-projects-issues
Copy link
Collaborator Author

Stefan Groschupf commented

Here is my code (as described in my blogpost on find23.net) as an example for all those running in the same problem.
Feel free to use commercial as open source - please credit 101tec Inc. in your java doc :-)

@spring-projects-issues
Copy link
Collaborator Author

Lari Hotari commented

There's a nice and simple solution by Alexander V. Zinin in this discussion thread:
http://forum.springframework.org/showthread.php?t=55183

@spring-projects-issues
Copy link
Collaborator Author

Lari Hotari commented

Properties can be injected in to beans by using the PropertyOverriderConfigurer, this works also beans created with context:component-scan
This was the solution I was looking for. I've added an issue about documenting this in the reference documentation.
http://jira.springframework.org/browse/SPR-4907

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

We have a common @Value annotation since 3.0 M1 already, typically used with embedded "#{...}" expressions. As of 3.0 M3, it can also be applied to bean property setters, supports "${...}" placeholders, and is reused for JavaConfig-style configuration classes (which are part of 3.0 core now).

Juergen

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0 M3 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants