Backend Development 10 min read

Guide to Integrating Spring Framework, Spring MVC, and MyBatis

This article provides a step‑by‑step tutorial on building a Spring container, configuring Spring MVC with DispatcherServlet, setting up essential beans such as multipartResolver, custom handler mapping, handler adapter, view resolver, component scanning, and finally integrating MyBatis with SqlSessionFactoryBean and SqlSessionTemplate for a complete Java backend solution.

Java Captain
Java Captain
Java Captain
Guide to Integrating Spring Framework, Spring MVC, and MyBatis

The article explains how to assemble a Spring container by registering core listeners in <web.xml> , including ContextLoaderListener , RequestContextListener , and IntrospectorCleanupListener , and by adding a CharacterEncodingFilter to handle UTF‑8 encoding.

It then shows the registration of org.springframework.web.servlet.DispatcherServlet as the front controller, with its own spring-mvc.xml configuration file, using a servlet mapping like *.do .

Key beans defined in spring-mvc.xml include a multipartResolver for file uploads, a custom handlerMapping that extends RequestMappingHandlerMapping , and a handlerAdapter that configures message converters, a conversion service for date handling, and a customized Jackson ObjectMapper to format dates as strings.

The view layer is set up with an InternalResourceViewResolver that resolves JSP pages using the prefix / and suffix .jsp , and the configuration enables component scanning for @Controller , @RestController , and @ControllerAdvice annotated classes in the io.flysium package.

Finally, the guide demonstrates MyBatis integration by declaring SqlSessionFactoryBean (pointing to a data source and MyBatis config file) and SqlSessionTemplate beans, completing the end‑to‑end backend setup.

Optional configurations such as LocaleResolver , ThemeResolver , HandlerExceptionResolver , and additional view resolvers are mentioned for further customization.

Code snippets:

contextConfigLocation
classpath*:webconfig/service-all.xml
org.springframework.web.context.ContextLoaderListener
org.springframework.web.context.request.RequestContextListener
org.springframework.web.util.IntrospectorCleanupListener
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
forceEncoding
false
encodingFilter
/*
Spring-MVC
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath*:spring/spring-mvc.xml
1
Spring-MVC
*.do
JavaBackend DevelopmentSpringMyBatisSpring MVCXML Configuration
Java Captain
Written by

Java Captain

Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.