0

I'm trying to handle multiple web modules in a spring MVC application. Let's say I have two modules : financial module and warehousing module. They have their own business processes, but there's some common processes like LDAP authentication and searches ... and also dependencies between them. So I want to keep them in a single web application, with two different requestmappings : /finance/* and warehouse/*

My question is similar to this one : How should I build a modularized enterprise application which must use Spring and JPA?

So my first approach was to create an enum to store the modules list :

public enum WebApplicationModule {
FINANCE("/finance", "Finance Module"),
WAREHOUSE("/warehouse", "Warehouse Module");    

private final String moduleTitle;   
private final String moduleRequestMapping;

WebApplicationModule(String moduleRequestMapping, String moduleTitle) {
    this.moduleRequestMapping = moduleRequestMapping;
    this.moduleTitle = moduleTitle;
}

public String getModuleTitle() {
    return moduleTitle;
}
public String getModuleRequestMapping() {
    return moduleRequestMapping;
}

}

Then I created two abstract controllers :

@Controller
@RequestMapping(value = {WebApplicationModule.FINANCE.getModuleRequestMapping()})
public abstract class FinanceAbstractController {
private final String VIEWS_FOLDER = "finance";
}

and

@Controller
@RequestMapping(value = {WebApplicationModule.WAREHOUSE.getModuleRequestMapping()})
public abstract class WarehouseAbstractController {
private final String VIEWS_FOLDER = "warehouse";
}

All controllers in the modules will extend them.

The goal is to handle RequestMappings dynamically : /finance/* and warehouse/*. I also want to be able to display dynamically a menu (ul li ahref) to choose module on the header of the web page.

I know it's not working because RequestMapping's value have to be a constant value, that's why I'm asking you the best way to do this.

Thanks

Community
  • 1
  • 1
Ilalaina
  • 41
  • 4

1 Answers1

0

Do you want to provide a shared request mapping prefix? Like all FinanceControllers maps url started with "/finance/..".

What about using different DispatcherServlet at the first place?

<servlet>
    <servlet-name>finance</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>finance</servlet-name>
    <url-pattern>/finance/*</url-pattern>
</servlet-mapping>

<servlet>
    <servlet-name>warehouse</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>warehouse</servlet-name>
    <url-pattern>/warehouse/*</url-pattern>
</servlet-mapping>
Yugang Zhou
  • 7,123
  • 6
  • 32
  • 60