如何将当前Connection从Spring上下文传递到iReport? [英] How to pass current Connection from Spring context to iReport?

查看:50
本文介绍了如何将当前Connection从Spring上下文传递到iReport?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Spring上下文中获取当前连接,然后传递给我的JasperPrint对象.

I want to get the current connection from Spring context and then pass to my JasperPrint object.

类似这样的东西:

 //java.sql.Connection con = StringContext.getConnection();
 JasperPrint jp = JasperFillManager.fillReport("reports/my_report.jasper", parameters, con);

我如何使它起作用?

ps:我已经尝试过使用DataSourceUtils,但是getConnection()方法需要一个DataSource对象作为参数,在哪里可以得到这个对象?

ps: I've tried using DataSourceUtils, but the getConnection() method needs a DataSource object as parameter, where do I get this object?

推荐答案

您可能需要这样的内容:

You may need something like this:

@Component
class JRExporter{
    @Autowired
    protected DataSource localDataSource;

    public void export(){
      java.sql.Connection con = localDataSource.getConnection()
      JasperPrint jp = JasperFillManager.fillReport("reports/my_report.jasper", parameters, con);
    }

这篇关于如何将当前Connection从Spring上下文传递到iReport?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆