java - Difference Between web-app's context-param and servlet's init-param? -


i'm using spring mvc. in controller class, want use @value annotation inject value comes properties file:

@value("${upload.dir}") private string uploaddir; 

so need put property-placeholder somewhere.

the web.xml typical:

<servlet>     <servlet-name>mvc-dispatcher</servlet-name>     <init-param>         <param-name>contextconfiglocation</param-name>         <param-value>classpath:spring/mvc-dispatcher-servlet.xml</param-value>     </init-param>     ... </servlet>  <context-param>     <param-name>contextconfiglocation</param-name>     <param-value>classpath:spring/business-context.xml</param-value> </context-param> 

first, put placeholder in business-context.xml. doesn't work: "could not autowire field".

then put in mvc-dispatcher-servlet.xml, works.

so i'm confused these 2 contexts, same 1 or different? because beans defined in business-content.xml can autowired, @value doesn't work.

i don't want put placeholder in both xml files 'cause have long 'location' property. business-context.xml used jobs, cannot omitted.

any way make placeholder defined in business-context.xml become visible in mvc-dispatcher-servlet.xml well?

a beanfactorypostprocessor property-placeholder operate (and visible) application context defined in. design. no cannot make property-placeholder parent visible child context (well nasty hacks could).

as work around following in business-context.xml

<util:properties id="applicationproperties" location="path-to-your-very-long-location" /> <context:property-placeholder properties-ref="applicationproperties" /> 

and in mvc-dispatcher-servlet.xml.

<context:property-placeholder properties-ref="applicationproperties" /> 

define same <context:property-placeholder ../> in both xml context , reference loaded properties. added advantage properties loaded once.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -