我有带有条目的属性文件report.properties (\WEB-INF\classes\properties\report.properties):
reportTemplate = reports/report5.jrxml
和applicationContext-reports.xml (\WEB-INF\config\applicationContext-reports.xml) 与条目:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:properties/report.properties"/>
</bean>
网页.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/applicationContext-reports.xml
</param-value>
</context-param>
在我的控制器中,我有:
private @Value("${reportTemplate}") String reportTemplatePath;
但是当我打印它来检查它的值时:
System.out.println("reportTemplatePath="+reportTemplatePath);
而不是输出:(reports/report5.jrxml
取自属性文件)它给出reportTemplatePath=${reportTemplate}
编辑:为了清楚起见并显示其所在位置,此处复制了 OP 评论System.out.println
。
@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";
}
}