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

Support placeholders in @Resource annotation configurations [SPR-5656] #10327

Closed
spring-projects-issues opened this issue Apr 7, 2009 · 3 comments
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

nicolas de loof opened SPR-5656 and commented

Using @Resource is a nice option to get dependency injection. You just can't get support for propertyPlaceholder. For example, getting some configuration URL I'd like to write :

@Resource( name="${my.server.URL}" )
private URL serverUrl;


Affects: 2.5.6

Referenced from: commits 859497b

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Good idea! We're supporting placeholders for @Value values in 3.0 M3 already, so supporting them for @Resource names as well makes a lot of sense.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

nicolas de loof commented

The changes in #955 only support Bean injection (bean ID beeing configurable), not value injection with @Resource annotation. I'd like to write the following and get Spring use type conversion to resolve the placeholder as URL.

@Resource( name="${my.server.URL}" )
private URL serverUrl;

with properties :
my.server.URL = http://www.myserver/foo

But maybe the @Resource annotation is not designed for such use-case. Is the @Value annotation a new Spring3 class ? Is there something comparable in commons-annotation (I'd like to be framework agnostic)

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Ah good point, I missed your original intent there.

However, @Resource is not really designed for this indeed... It's a resource object lookup mechanism based on resource names. Using placeholders will only affect the name part, with the lookup still happening.

@Value is designed for resolving a value (through EL and/or placeholders in 3.0 M3) and injecting it right away. It is Spring specific but it seems to be exactly what you need. I'm not aware of a common annotation with similar semantics... except possibly for JSF 2.0's @ManagedProperty annotation (which does not support placeholders but rather just EL, though).

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