In the meantime I figured out how to approach this.
My first assumption was wrong that Tomcat does not support Spring Beans. I was confused with EJB (Java Enterprise Beans). But Spring Beans are in fact supported.
I decided to share my findings as using spring beans together with freemarker is hardly documented but very powerful to use in your templates. So in case anyone would like to to the same and load template via beans, please be advised:
In the end, in the freemarker template it shall be enough to say
${textbausteine.load('id_textbaustein')}
and to output then the template loaded from a database.
To make that happen, you have to create a spring bean with the ID textbausteine and a method called “load” that accepts the ID of the template as parameter.
package org.myorg.beans.textbausteine;
@Service
public class TextbausteineLoader {
public String load(String textbausteinID) {
return template_loaded_from_database;
}
}
Then in your workflow project add two files under src/main/webapp/WEB-INF the files web.xml and applicationContext.xml that shall look like this:
web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
applicationContext.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:annotation-config />
<bean id="textbausteine" class="org.myorg.beans.textbausteine.TextbausteineLoader" />
</beans>
Don’t forget to include Spring dependencies in the POM.XML
<dependency>
<groupId>org.camunda.bpm</groupId>
<artifactId>camunda-engine-spring</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
Then it should work and you will get the loaded result.
P.S. What is still an issue are nested spring beans, please see here for the discussion https://forum.camunda.io/t/nested-spring-beans-in-freemarker/4039