Question

I have properties file report.properties (\WEB-INF\classes\properties\report.properties) with entry :

reportTemplate = reports/report5.jrxml

and applicationContext-reports.xml (\WEB-INF\config\applicationContext-reports.xml) with entry:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:properties/report.properties"/>
</bean>

web.xml:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/config/applicationContext-reports.xml
    </param-value>
</context-param>

In my controller I have:

private @Value("${reportTemplate}") String reportTemplatePath;

But when i print this to check its value as:

System.out.println("reportTemplatePath="+reportTemplatePath);

Instead of output:reports/report5.jrxml (taken from property file ) it gives reportTemplatePath=${reportTemplate}

Edit: Copied OP comment here for clarity and to show where the System.out.println is located.

@Controller
public class myController {
    private @Value("${reportTemplate}") String reportTemplatePath;
    // other field declarations... 

    @RequestMapping(value="report.htm", method=RequestMethod.GET) public String showReport() throws JRException{
        ...
        System.out.println("reportTemplatePath="+reportTemplatePath);
        ...
        return "report";
    }
}
Was it helpful?

Solution

I guess that applicationContext-reports.xml belongs to the root application context, whereas controller is declared in context of DispatcherServlet. If so, note that PropertyPlaceholderConfigurer is configured at per-context basis, therefore you need to declare it in ...-servlet.xml as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top