Springboot Inside of Ignition Gateway Module

I'd like to integrate Spring into my current Ignition gateway module to provide a management API for our application and to make the core functionality a bit more portable for different use cases. Is this something that is possible with the architecture of Ignition or has anyone done something similar? After digging through the docs and forums I have not found anything related to this so any help is appreciated.

It may be possible if you expected zero integration with Ignition and its own embedded web server instance, and your module just tried to boot up its own embedded Springboot/Tomcat setup, running a 2nd HTTP server in parallel... but yuck.

And that's assuming there's no ClassLoader issues or anything like that.

I'm not familiar with Spring, but a module can mount its own servlets into Ignition's URL namespace.

Use yourModuleContext.getWebResourceManager(), then .addServlet(...)

I've done this actually, and it wasn't easy to figure out, but only takes a little bit of code.

There are some weird class loader issues that I had to work around with the following:


    @Synchronized
    private void initializeSpringContext() {
        // force spring to use the current classes classLoader to load spring dependencies
        var threadClassLoader = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

        springContext = new AnnotationConfigApplicationContext(SpringContextConfig.class);
        this.beanFactory = springContext.getAutowireCapableBeanFactory();

        Thread.currentThread().setContextClassLoader(threadClassLoader); // reset the class loader to prevent any unintended side effects
    }

I didn't do any xml/file based configuration and instead opted to do a configuration class. I did manage to get JPA, JTA, DI and web services working. Going forward, Java changing the servlet namespace under (javax is now jakarta) has basically broken the APIs I was using to integrate spring boot webservices with Ignition.

1 Like