這篇文章將為大家詳細(xì)講解有關(guān)Spring Boot + Mybatis + Spring MVC環(huán)境配置中Spring Boot如何實(shí)現(xiàn)初始化以及依賴(lài)添加,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
成都創(chuàng)新互聯(lián),專(zhuān)注為中小企業(yè)提供官網(wǎng)建設(shè)、營(yíng)銷(xiāo)型網(wǎng)站制作、成都響應(yīng)式網(wǎng)站建設(shè)公司、展示型網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站等服務(wù),幫助中小企業(yè)通過(guò)網(wǎng)站體現(xiàn)價(jià)值、有效益。幫助企業(yè)快速建站、解決網(wǎng)站建設(shè)與網(wǎng)站營(yíng)銷(xiāo)推廣問(wèn)題。
看一下Spring Boot官方的介紹http://spring.io/projects/spring-boot :
Spring Boot讓開(kāi)發(fā)者省去了大多數(shù)Spring的配置,讓其只需要關(guān)注主要的開(kāi)發(fā)和進(jìn)行少量的Spring配置。
嵌入了Tomcat,已定義好大多數(shù)的依賴(lài)關(guān)系,簡(jiǎn)化了項(xiàng)目的構(gòu)建配置。我們?cè)谑褂玫臅r(shí)候不用關(guān)心框架之間的兼容性,適用版本等問(wèn)題,想使用的東西,僅僅添加一個(gè)配置就可以了,所以使用spring boot非常適合構(gòu)建微服務(wù)。
第一步,訪問(wèn)https://start.spring.io/ 生成一個(gè)spring boot項(xiàng)目
生成之后會(huì)下載一個(gè)壓縮包,解壓后,在Eclipse中Import為Maven項(xiàng)目
第二步,添加額外需要的依賴(lài),如Mybatis
pom.xml內(nèi)容如下:
<?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文件中默認(rèn)有兩個(gè)模塊:
spring-boot-starter:核心模塊,包括自動(dòng)配置支持、日志和YAML;
spring-boot-starter-test:測(cè)試模塊,包括JUnit、Hamcrest、Mockito。
開(kāi)發(fā)環(huán)境的調(diào)試
熱啟動(dòng)在正常開(kāi)發(fā)項(xiàng)目中已經(jīng)很常見(jiàn)了吧,雖然平時(shí)開(kāi)發(fā)web項(xiàng)目過(guò)程中,改動(dòng)項(xiàng)目啟重啟總是報(bào)錯(cuò);但springBoot對(duì)調(diào)試支持很好,修改之后可以實(shí)時(shí)生效,需要添加以下的配置:
<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>
關(guān)于“Spring Boot + Mybatis + Spring MVC環(huán)境配置中Spring Boot如何實(shí)現(xiàn)初始化以及依賴(lài)添加”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
網(wǎng)站標(biāo)題:SpringBoot+Mybatis+SpringMVC環(huán)境配置中SpringBoot如何實(shí)現(xiàn)初始化以及依賴(lài)添加
標(biāo)題來(lái)源:http://jinyejixie.com/article38/iihepp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號(hào)、網(wǎng)站營(yíng)銷(xiāo)、網(wǎng)站收錄、ChatGPT、品牌網(wǎng)站制作、網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)