0

春のアプリケーションをコーディングしています。私はこのような予定の仕事をしています。

@Async
@Scheduled(cron = "0 0 16 * * ?")
public void createReport()
{
    // argJasperPath = /WEB-INF/jasperFiles/myreport.jasper
    JasperPrint jasperPrint = JasperFillManager.fillReport(argJasperPath, argReportParams, argDataSource);
    JasperExportManager.exportReportToPdfFile(jasperPrint, argOutputPath);
}

これは毎日16:00に実行され、レポートを作成します。レポートの生成にJasperReportsを使用しています。/WEB-INF/jasperFiles/myreport.jasperの下にmyreport.jasperファイルがあり、レポートの生成中にジョブを実行すると、が表示されます。FileNotFound exception

スケジュールされた方法でジャスパーファイルにアクセスするにはどうすればよいですか?

4

1 に答える 1

0
@Autowired
ServletContext context;

@Async
@Scheduled(cron = "0 0 16 * * ?")
public void createReport()
{
    // argJasperPath = /WEB-INF/jasperFiles/myreport.jasper
    JasperPrint jasperPrint = JasperFillManager.fillReport(context.getRealPath(argJasperPath), argReportParams, argDataSource);
    JasperExportManager.exportReportToPdfFile(jasperPrint, argOutputPath);
}

自動配線ServletContextすると、次のようなディレクトリに到達できます。(context.getRealPath(argJasperPath)

于 2012-08-16T12:55:51.703 に答える