3

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

1 に答える 1

7

それはルートアプリケーションコンテキストに属していると思いapplicationContext-reports.xmlますが、コントローラーはのコンテキストで宣言されていますDispatcherServletPropertyPlaceholderConfigurerその場合、はコンテキストごとに構成されているため、...-servlet.xml同様に宣言する必要があることに注意してください。

于 2012-01-31T16:37:45.983 に答える