Quickly Build a Maven + Spring + SpringMVC + MyBatis + SpringBoot Project in IntelliJ IDEA
This tutorial walks through creating a lightweight Java web project using Maven, Spring, SpringMVC, MyBatis, and SpringBoot in IntelliJ IDEA, covering project setup, datasource configuration, Spring annotations, MyBatis integration, deployment settings, and optional Redis and Druid components.
The most popular Java web stack today is SSM (Spring, SpringMVC, MyBatis), and SpringBoot’s lightweight, annotation‑driven approach has become equally popular. This guide shows how to quickly scaffold a Maven‑based project that combines Spring, SpringMVC, MyBatis, and SpringBoot in IntelliJ IDEA.
1. Create the project – Use Spring Initializr in IntelliJ, add the basic dependencies Web, MySQL, and MyBatis, and generate the project (GitHub repo: https://github.com/HowieYuan/SSM-SpringBoot).
2. Configure the data source – Set up the database connection information in application.properties and optionally configure IDEA’s data source view.
spring.datasource.url = jdbc:mysql://<span style="color: rgb(92, 99, 112); font-style: italic">//xx.xx.xx.x:xxx/xxx?characterEncoding=utf8&allowMultiQueries=true&useSSL=false</span>
spring.datasource.username = root
spring.datasource.password = 123456
spring.datasource.driver-class-name = com.mysql.jdbc.DriverKey properties include url, username, password, and driver-class-name (e.g., com.mysql.jdbc.Driver for MySQL).
3. Spring annotations – Use @Controller / @RestController for controllers, @Service for service layer, @Repository for mapper interfaces, @Component for generic beans, and @Configuration for configuration classes.
4. MyBatis integration – Declare mapper XML files, set mybatis.mapperLocations and mybatis.typeAliasesPackage in application.properties, and optionally configure additional MyBatis settings.
<mapper namespace="com.swit.dao.MyMapper">
...
</mapper>Mapper scanning can be done either with @MapperScan("com.swit.dao") on the main class or by annotating each mapper interface with @Mapper and @Repository.
5. Important SpringBoot annotations – @SpringBootApplication combines @Configuration, @EnableAutoConfiguration, and @ComponentScan, eliminating the need for those three annotations separately.
6. Deployment considerations – To package the application as a WAR for external servlet containers, extend SpringBootServletInitializer and override configure. Add the Spring Boot Maven plugin and the Maven compiler plugin to pom.xml for building.
<build>
<finalName>projectName</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>Cross‑origin support can be added via a custom CorsFilter component that sets the appropriate response headers.
@Component
public class CorsFilter implements Filter {
private String tokenHeader = "X_Auth_Token";
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) res;
HttpServletRequest request = (HttpServletRequest) req;
// set CORS headers ...
chain.doFilter(req, res);
}
// init and destroy omitted
}7. Optional components
• Redis – Add spring-boot-starter-data-redis dependency and configure connection properties in application.properties.
# Redis configuration
spring.redis.database=0
spring.redis.host=127.0.0.1
spring.redis.port=6379
spring.redis.password=123456
spring.redis.pool.max-active=15
spring.redis.timeout=0• Druid datasource – Include the Druid dependency and set pooling properties in application.properties.
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.filters=stat
spring.datasource.maxActive=20
spring.datasource.initialSize=5
spring.datasource.maxWait=60000
spring.datasource.minIdle=1
spring.datasource.validationQuery=select 'x'
spring.datasource.testWhileIdle=trueFinally, the author invites readers to like and share the tutorial.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
