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

Can not inject primitive values from property file using @Value annotation into servlet [SPR-8574] #13218

Closed
spring-projects-issues opened this issue Aug 1, 2011 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Aug 1, 2011

Lukas Vlcek opened SPR-8574 and commented

I am not able to inject primitive values from property file into servlet. Complete sample code can be found here: https://github.com/lukas-vlcek/SpringValueAnnotationTest

In a nutshell:

  1. I setup annotation driven config mode using <context:annotation-config />
  2. I read property file <util:properties id="values" location="WEB-INF/inject.properties" />
  3. Then in init() method of each servlet I call SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, config.getServletContext());
  4. Injection in servlet using @Autowired works fine but using @Value does not. More specifically see https://github.com/lukas-vlcek/SpringValueAnnotationTest/blob/master/src/main/java/org/test/springframework/inject/Bar.java Injecting using @Value annotation fails in this servlet.

Besides Bar servlet there two other servlets that work fine, these are Foo and Lorem servlets. I created these two working servlets to verify that @Value annotation works fine when not used directly on servlet (that is the case for Lorem) and in Foo servlet I show that the Properties object is loaded correctly using @Autowired annotation.

So the question is: is it possible to have primitive values from property file directly injected into servlet?


Affects: 3.0.5

Reference URL: http://forum.springsource.org/showthread.php?112716-Using-Value-to-inject-primitive-value-from-property-file-into-servlet-possible

Issue Links:

Referenced from: commits 8f23c66, 3ffc0a2

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Good catch! We had too strong an assertion in there which I've relaxed accordingly. Fixed for 3.0.6 as well as 3.1 RC1.

Juergen

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: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants