Import error templates from a external jar

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Import error templates from a external jar


I've a multi module project with multiple webapps serving different purposes but sharing same look and feel.
What I'm trying to achive is extract all the error templates into a separate jar file and include them as a maven dependency in each webapp.

What I've done so fare is creating a new module, define a main class with SpringBootApplication annotation, and defined multiple templates within the resources/templates/error folder.
I'm then adding this module as a dependency in the pom file of another webapp and run it as a war in Tomcat.
When I try to reach generate an error, Spring is not reading the custom error templates but generates the default whitelabel error page.

The next step in my test was to create a controller in my main webapp and reference from there a test template created in the inherited jar. This is working.
Another test I've done is to define an request mapping in my jar and try to reach that from the webapp, and that's working too.

I've tried to create also a TemplateEngine Bean with a template resolver that point to the jar, but maybe I'm doing something wrong...
Here the code for the TemplateEngine and the TemplateResolver that I've created
    public TemplateEngine errorTemplateEngine() {
        SpringTemplateEngine templateEngine = new SpringTemplateEngine();
        return templateEngine;

    private ITemplateResolver errorTemplateResolver() {
        final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
        return templateResolver;

Could you help me?