Skip to content

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

@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions