简体   繁体   中英

Abstract a web application using Spring

We have a web application that is domain specific. By domain specific I mean that some values and behaviour are hard coded and not generic enough to handle new domain. So we are in a phase of abstracting the application and make it more open to new domain.

We are using maven, spring and JSP. The idea is to have a project that is generic and one project by domain that would contain the resources. The final application would be a combination of the generic app and one of the domain resources.

I identified different elements that we need to abstract, and wanted to know the best practices to achieve the abstraction using Spring.

  • Static HTML page like contact us information.

The current implementation is a controller method coupled with a contact.jsp page.

@RequestMapping("/contact.htm")
public ModelAndView handleRequest(HttpServletRequest request,
        HttpServletResponse response) {
    return new ModelAndView("contact");
}

Spring is looking for a page contact.jsp in /WEB-INF/jsp/contact.jsp .

<bean id="viewResolver"
      class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
</bean

I added a new dependency that contains the contact.jsp . In my-resources.jar , I have the jsp file under /WEB-INF/jsp/contact.jsp . Is there a way to configure the viewResolver to fetch the file as a resource from the jar instead of fetching the file as a File on the file system?

  • UI

We have a radio button that allows the user to choose between several versions. Not all versions apply to all domain, so for one domain only 2 versions would be displayed, and for another domain, 4 versions would be displayed.

The idea is to create a property file in the my-resources.jar to configure the UI.

versions.supported = 2, 3

What is the best way to access the property file since it would be needed in almost all the controllers?

Because you are using maven, why not make your generic project package as war? This will solve your problem. Also you domain specific project can over ride generic project files if needed.I worked on a project with similar requirements. You will always find a case where you need to override generic project files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM