這篇文章將為大家詳細講解有關Spring Boot + Mybatis + Spring MVC環(huán)境配置中Spring Boot如何實現(xiàn)初始化以及依賴添加,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
成都創(chuàng)新互聯(lián),專注為中小企業(yè)提供官網(wǎng)建設、營銷型網(wǎng)站制作、成都響應式網(wǎng)站建設公司、展示型網(wǎng)站設計、成都做網(wǎng)站等服務,幫助中小企業(yè)通過網(wǎng)站體現(xiàn)價值、有效益。幫助企業(yè)快速建站、解決網(wǎng)站建設與網(wǎng)站營銷推廣問題。
看一下Spring Boot官方的介紹http://spring.io/projects/spring-boot :
Spring Boot讓開發(fā)者省去了大多數(shù)Spring的配置,讓其只需要關注主要的開發(fā)和進行少量的Spring配置。
嵌入了Tomcat,已定義好大多數(shù)的依賴關系,簡化了項目的構建配置。我們在使用的時候不用關心框架之間的兼容性,適用版本等問題,想使用的東西,僅僅添加一個配置就可以了,所以使用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模塊
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。
開發(fā)環(huán)境的調試
熱啟動在正常開發(fā)項目中已經(jīng)很常見了吧,雖然平時開發(fā)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>
關于“Spring Boot + Mybatis + Spring MVC環(huán)境配置中Spring Boot如何實現(xiàn)初始化以及依賴添加”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
網(wǎng)站標題:SpringBoot+Mybatis+SpringMVC環(huán)境配置中SpringBoot如何實現(xiàn)初始化以及依賴添加
標題來源:http://aaarwkj.com/article38/iihepp.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供微信公眾號、網(wǎng)站營銷、網(wǎng)站收錄、ChatGPT、品牌網(wǎng)站制作、網(wǎng)站建設
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)