Spring Boot additional servlet registration

875 Views Asked by At

I have a Spring Boot Web MVC application, that sits at the root of the application. I am trying to add a third party servlet (CKFinder Java connector) to this application.

I have achieved this with the following:

    @Bean
    public ServletRegistrationBean<CKFinderServlet> registerCkFinder() {
        ServletRegistrationBean<CKFinderServlet> bean =
                new ServletRegistrationBean<>(new CKFinderServlet(), "/ckfinder/*");
        bean.setLoadOnStartup(-1);
        bean.setInitParameters(
                Map.of("scan-path", "<package name>"));
        bean.setMultipartConfig(new MultipartConfigElement("/tmp/upload"));
        return bean;
    }

The main website continues to work correctly, but when I try and hit the CKFinder servlet, I get a series of errors that show initialisation issues while errors while trying to evaluate @Value(...) parameters while auto-wiring my interceptors and controllers (I don't fully understand why it is constructing the controllers).

Having done some investigation, I get the feeling its to do with application contexts!? I do want to share some context information (such as the security information, logged in user etc), but I otherwise don't really need any of the other Spring MVC goodness while executing the servlet.

My question is threefold:

  1. Am I right in thinking its to do with contexts?
  2. How do I register the servlet such that it when called the @Value() and other Spring stuff evaluates correctly? OR
  3. How do I register the servlet with a new context such that it doesn't inherit, and try to initialise, all the Spring MVC components?

I am also considering putting a controller wrapper around the servlet, but that seems overkill for something that should "just work".

0

There are 0 best solutions below