Inject spring bean into Dynamic Schema Processor in Pentaho


When creating custom classes for Pentaho BA Server, we can ask Spring to create their instances for us, by simply putting necessary settings in one of the application context configuration files under ../biserver-ee/pentaho-solutions/system. But what if our new class has to be created outside of spring and we still need to inject dependencies from the context created for Pentaho? Particularly this becomes a problem when we would like to inject some dependencies into Dynamic Schema Processor.

Where the Dynamic Schema Processor is created

When we create an analysis datasource inside Pentaho BA Server, apart from uploading the schema file itself we are allowed to define parameters for this schema. One of them is DynamicSchemaProcessor that allows us to specify what class should be run before using the schema itself, allowing us for instance to modify the schema before it is used. Before I started looking into the solution for the problem I wanted to see where and how these objects are created. I hoped that maybe knowing that, would allow me to inject dependencies I needed, with some clever and small hack. I soon found that the code responsible for handling DSPs was inside class called MondrianCatalogHelper. Have a look at the code below:

Obviously this does not leave much space for any potential hacks. As well, I felt that what I try to achieve is way too ordinary, and there must be a way other than changing the code of MondrianCatalogHelper itself.


And I was right! It turned out that there is a static method somewhere inside Pentaho that allows you to retrieve beans initiated in spring context created for the bi server. Here is how it looks like the code:

In my case the Foo bean was defined inside applicationContext-spring-security.xml under ../biserver-ee/pentaho-solutions/system. It is important to remember than in order to use PentahoSystem.get() to retrieve certain bean it has to be marked with special tag inside its definition.

For namespace pen one has to modify beans tag, so it looks like this:


Please join discussion