Search code examples
spring-bootjodd

Is there a way how to run madvoc inside of spring boot?


Is there a way to run Madvoc web microframework inside of Spring Boot?

Spring Boot allows integration of other technologies (we experimented with Apache Wicket running under Spring Boot).

Is this possible for JODD madvoc? Is there any proper configuration example?

EDIT #1 I tried to add Spring Boot servlet filter configuration for Madvoc, but can't see Madvoc init output like this one:

INFO jodd.madvoc.Madvoc - Madvoc starting... 
INFO jodd.madvoc.Madvoc - Default Madvoc web application created.

This is how my init code looks like ...

@Configuration
public class MadvocInitializer implements ServletContextInitializer {

    @Override
    public void onStartup(ServletContext sc) throws ServletException {
        FilterRegistration filter = sc.addFilter("madvoc", MadvocServletFilter.class);
        filter.setInitParameter("madvoc.webapp","app.web.jodd.AppWebApplication");

        EnumSet NON_ASYNC_DISPATCHER_TYPES =
                EnumSet.of(DispatcherType.FORWARD, DispatcherType.INCLUDE,DispatcherType.REQUEST);

        filter.addMappingForUrlPatterns(NON_ASYNC_DISPATCHER_TYPES, true, "/jodd/*");

        System.out.println("+++ MADVOC FILTER");
    }
}

EDIT #2 Filter configuration references 'AppWebApplication' which looks like below. I can see print message from 'registerMadvocComponents' code, so something is definitely running.

public class AppWebApplication extends WebApplication {

    @Override
    public void registerMadvocComponents() {
        super.registerMadvocComponents();

        System.out.println("+++ MADVOC FILTER - configuration");

        registerComponent(MadvocConfig.class);
       // registerComponent(MyRewriter.class);
    }

}

Solution

  • Ok, in the nutshell here we have Servlets 3.x way of registering Madvoc filter that is going to register everything.

    Please check working example with Servlets 3 here.

    Your code looks fine, but here is what you can check:

    1. Maybe Springboot simply hides the logs from Jodd and you are not seeing it is working.

    2. There might be a problem if you filter to /jodd/*:) By default, actions will be mapped to e.g. /index.html instead of /jodd/index.html. Hence, you will not be able to run actions. To test this, please map filter to root (/*) and see if you can reach your Madvoc actions now :)

    To inject Spring into the Madvoc actions - check class PetiteMadvocController. This one injects Petite beans in the madvoc (yeah, who needs Spring anyway:). Basically, you just need to create action class in the Springs application context.