Category Archives: jasper

[Jaspersoft] Creating custom Spring managed DataSource

Problem Statement

Often for reporting, we need to gather data from many diverse resources. In case we are using Jaspersoft server, its sometimes not possible to manage with the existing DataSources provided by Jaspersoft. In this article, we will explore step by step how to write our custom DataSource. The main challenge is that in the given examples like the WebScraperDataSource, the factory beans are not Spring managed. They are instantiated by the framework through a no-argument constructor by reflection. In case I need to talk to other Spring managed beans, it becomes incredibly difficult. In the below example, I will try to put a hack so that we can use our own Spring managed DataSourceFactory.

Dev Environment Setup

I would need to hook into the Jaspersoft’s framework and for that, I need to create my own jar which can then be deployed into the WEB-INF/lib directory of Jaspersoft’s webapp. I am using Maven. The following dependencies need to be declared:

Note that some of these are not available in Maven public repos and need to manually deployed from the webapps/WEB-INF/lib directory:

Spring bean configuration

Jaspersoft works with Spring, thanks God for that!



Finally, this is what the Spring file looks like:

Information flow




Making our custom Query appear on the Jaspersoft

We need to make further configuration changes before our custom query appears on the Jaspersoft screen.

Make an entry in the applicationContext-rest-services.xml

Register your factory at WEB-INF/classes/

Make the following entry:


Generate report

We are all set now to generate a report. Create the DataSource we have just now defined. Then create a JRXML and define the query there:

Link the DataSource and the JRXML. You need to define an Input as well. Then run the report. You should see the below report:


The sources for this can be found here: