Spring Boot + Mybatis + Spring MVC環境配置(一) :Spring Boot初始化,依賴新增
最近在搭建一個Spring Boot + Mybatis + Spring MVC的環境,折騰來折騰去,兩三天才搞定,記錄下大概過程和遇到的錯誤
看一下Spring Boot官方的介紹 http://spring.io/projects/spring-boot :
Spring Boot讓開發者省去了大多數Spring的配置,讓其只需要關注主要的開發和進行少量的Spring配置。
嵌入了Tomcat,已定義好大多數的依賴關係,簡化了專案的構建配置。我們在使用的時候不用關心框架之間的相容性,適用版本等問題,想使用的東西,僅僅新增一個配置就可以了,所以使用spring boot非常適合構建微服務。
第一步,訪問 https://start.spring.io/ 生成一個spring boot專案
生成之後會下載一個壓縮包,解壓後,在Eclipse中Import為Maven專案
第二步,新增額外需要的依賴,如Mybatis
pom.xml內容如下:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.kai</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>demo</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.4.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency> <!-- <dependency> <groupId>io.kwy.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> <version>1.5.3.1.RELEASE</version> </dependency> --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.4.6</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.3.2</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j</artifactId> <version>2.11.1</version> <type>pom</type> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> </dependency> <dependency> <groupId>com.zaxxer</groupId> <artifactId>HikariCP</artifactId> <version>3.2.0</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <fork>true</fork> </configuration> </plugin> </plugins> </build> </project>
引入web模組
Spring Boot Web Starter
Starter for building web, including RESTful, applications using Spring MVC. Uses Tomcat as the default embedded container
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
pom.xml檔案中預設有兩個模組:
spring-boot-starter:核心模組,包括自動配置支援、日誌和YAML;
spring-boot-starter-test:測試模組,包括JUnit、Hamcrest、Mockito。
開發環境的除錯
熱啟動在正常開發專案中已經很常見了吧,雖然平時開發web專案過程中,改動專案啟重啟總是報錯;但springBoot對除錯支援很好,修改之後可以實時生效,需要新增以下的配置:
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <fork>true</fork> </configuration> </plugin> </plugins> </build>
完整環境下載地址: https://github.com/CatherineHu/Spring-Boot-Mybatis-MVC
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10314474/viewspace-2200331/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Spring Boot + Mybatis + Spring MVC環境配置(二):Mybatis Generator配置Spring BootMyBatisMVC
- Spring Boot + Mybatis + Spring MVC環境配置(三):DataSource配置Spring BootMyBatisMVC
- Spring Boot + Mybatis + Spring MVC環境配置(四):MVC框架搭建Spring BootMyBatisMVC框架
- Spring Boot + Mybatis + Spring MVC環境配置(五):templates模板使用Spring BootMyBatisMVC
- Spring Boot:Spring Boot配置MybatisSpring BootMyBatis
- Spring Boot 起步依賴Spring Boot
- spring、spring MVC、spring BootMVCSpring Boot
- Spring Boot - Profile不同環境配置Spring Boot
- Spring Boot 基本配置之依賴管理starter pomSpring Boot
- SMM(spring +springmvc+mybatis)依賴註解等環境配置SpringMVCMyBatis
- Spring Boot:Spring Boot配置SwaggerSpring BootSwagger
- spring boot環境抽象Spring Boot抽象
- Spring boot學習(三) Spring boot整合mybatisSpring BootMyBatis
- spring boot學習4 多環境配置Spring Boot
- 深入淺出Spring Boot 起步依賴和自動配置Spring Boot
- Spring Boot 整合 MyBatisSpring BootMyBatis
- Spring Boot & 配置Spring Boot
- Spring Boot系列(三):Spring Boot整合Mybatis原始碼解析Spring BootMyBatis原始碼
- Spring MVC和Spring Boot的區別 - hackernoonMVCSpring Boot
- Spring MVC 到 Spring Boot 的簡化之路MVCSpring Boot
- Spring Boot學習筆記:Spring Boot核心配置Spring Boot筆記
- Spring boot學習(二) Spring boot基礎配置Spring Boot
- Spring boot學習(五)Spring boot整合Mybatis Generator以及PageHelperSpring BootMyBatis
- Spring Boot 2.4 對多環境配置的支援更改Spring Boot
- spring boot 配置 JPASpring Boot
- Spring Boot核心配置Spring Boot
- 基於spring boot 及mybatis的web開發環境搭建Spring BootMyBatisWeb開發環境
- Spring Boot MyBatis配置多種資料庫Spring BootMyBatis資料庫
- Spring Boot學習(一)——Spring Boot介紹Spring Boot
- Spring Boot系列(一):Spring Boot快速開始Spring Boot
- Spring Boot系列(一):Spring Boot 入門篇Spring Boot
- IDEA配置SSM(Spring-Spring MVC-MyBatisIdeaSSMSpringMVCMyBatis
- Linux系統CentOS 7配置Spring Boot執行環境LinuxCentOSSpring Boot
- Spring Boot —— 整合 MyBatis-PlusSpring BootMyBatis
- Spring Boot 教程 - MyBatis-PlusSpring BootMyBatis
- Spring Boot使用MyBatis Generator、SwaggerSpring BootMyBatisSwagger
- Spring boot學習(八)Spring boot配置ehcache快取框架Spring Boot快取框架
- Spring boot學習(九)Spring boot配置郵件傳送Spring Boot