0

I have a situation and im trying to figure out why it is so. The scenario is I have a class A that implements an operation exposed by a webservice. For each request for the operation a new instance of A is created. The entire thing is manged by Spring internally and I am not sure how exactly the Class A in instantiated by the webservice.

Now i have a class variable whose value i want to inject during runtime through

@Value("${someValue}") String someVariable

someValue is defined a system property. But each of the beans created has someVariable as NULL.

I tried the same thing in another class annotated with @Configuration in the same package and it is resolving the variable fine.

So, Im thinking if the ability to inject through @Value depends on the way a bean is created like @Component, @Configuration-@Bean, XML definiti

broun
  • 2,483
  • 5
  • 40
  • 55

1 Answers1

0

Not really. Actually You can inject value with @Value in both the component scan bean and xml definition bean. But pay attention to this, It depends on which xml file that you put the Placeholder in, it just valids in the per-container. For example, you put it in applicationContext, then the bean create in xxx-servlet.xml can not inject value with @Value.

OQJF
  • 1,350
  • 9
  • 12
  • Im sorry i dont get what you say in the second part of your answer. "It depends on which xml file that you put the Placeholder in, it just valids in the per-container. For example, you put it in applicationContext, then the bean create in xxx-servlet.xml can not inject value with @Value" – broun Mar 28 '13 at 07:29
  • OK, here is what it is, for example you put those values in a properties file and you want to use it, so you should config the placeholer in the xml config file, then which xml file you config it can determine which bean that can use @Value to inject the value. – OQJF Mar 28 '13 at 07:40
  • I dont understand propertyplaceholder configurer can pickup the properties rt. Why do we need to "config" each property specifically? I would mean we need to do some "config" stuff for every value we like to use placeholder for, – broun Mar 28 '13 at 07:49
  • You misunderstood my mean, I mean we put all the values we want to use in a property file and use placeholder to import the file, then we can use all the values, seems you should check the Spring reference. – OQJF Mar 28 '13 at 08:09