次のエントリを持つプロパティ ファイル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>
web.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";
}
}