1、原始Springboot環境
外網環境下利用idea開發工具
要准備好maven 與jdk環境,這里用的maven360與jdk1.8
沒有該功能可自行百度進行相關插件的安裝,可參考如下鏈接
https://blog.csdn.net/weixin_37717108/article/details/86755465
安裝插件后點擊next后可能會出現問題看具體出錯原因,1網絡不好(多試幾次),2.需要配置代理(自行百度)
根據自己的項目名稱進行如下設置
看自己的需要選擇相應的依賴及springboot的版本
關於相關依賴的作用可自行百度每個插件的作用,選擇自己需要的。
看好項目名及項目位置,一般不需要修改
完成后在idea中打開項目
選擇File->Settings->搜索Maven
配好settings.xml路徑找好自己的倉庫,改好maven版本
下面附上setting阿里雲倉庫的配置
1 <?xml version="1.0" encoding="UTF-8"?> 2 <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> 5 <localRepository>C:\SwordInstall\myselfLocalMavenRepo</localRepository> 6 <pluginGroups> 7 </pluginGroups> 8 <proxies> 9 </proxies> 10 <servers> 11 </servers> 12 <mirrors> 13 <mirror> 14 <id>alimaven</id> 15 <name>aliyun maven</name> 16 <url> 17 http://central.maven.org/maven2/ 18 </url> 19 <mirrorOf>central</mirrorOf> 20 </mirror> 21 </mirrors> 22 <profiles> 23 </profiles> 24 </settings>
File下的項目結構里相關項目和modules要改成相應的jdk8編譯
然后點擊maven的刷新,下載相關依賴,等下載完就好了,網絡不好可以多下幾次。
2.上面已經自動集成了SpringMVC 與thymeleaf模板(這是啥自行百度)
初始生成的環境如下紅框所標注,其余文件為我自己添加的
下面是POM文件,可以看出已經集成了spring(springboot)、jdbc、thymeleaf(只支持html的解析,不能解析jsp,解析jsp還需要引入tomcat-embed-jasper與jstl,在后面補充)、springmvc、mybatis、devtools(熱部署工具)、mysql、oracle、springboot配置文件解析(即解析yml文件)、lombok(注解工具,通過注解簡化model的書寫)
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 <modelVersion>4.0.0</modelVersion> 5 <parent> 6 <groupId>org.springframework.boot</groupId> 7 <artifactId>spring-boot-starter-parent</artifactId> 8 <version>2.2.2.RELEASE</version> 9 <relativePath/> <!-- lookup parent from repository --> 10 </parent> 11 <!-- 下面依次是組織、項目、版本、生成的包名、描述、打成什么包web應用為war包 --> 12 <groupId>com.open</groupId> 13 <artifactId>sword</artifactId> 14 <version>0.0.1-SNAPSHOT</version> 15 <name>sword</name> 16 <description>Demo project for Spring Boot</description> 17 <packaging>war</packaging> 18 <!-- jdk版本 --> 19 <properties> 20 <java.version>1.8</java.version> 21 </properties> 22 <!-- 各種依賴的插件 --> 23 <dependencies> 24 <dependency> 25 <groupId>org.springframework.boot</groupId> 26 <artifactId>spring-boot-starter-jdbc</artifactId> 27 </dependency> 28 <dependency> 29 <groupId>org.springframework.boot</groupId> 30 <artifactId>spring-boot-starter-thymeleaf</artifactId> 31 </dependency> 32 <dependency> 33 <groupId>org.springframework.boot</groupId> 34 <artifactId>spring-boot-starter-web</artifactId> 35 </dependency> 36 <dependency> 37 <groupId>org.mybatis.spring.boot</groupId> 38 <artifactId>mybatis-spring-boot-starter</artifactId> 39 <version>2.1.1</version> 40 </dependency> 41 42 <dependency> 43 <groupId>org.springframework.boot</groupId> 44 <artifactId>spring-boot-devtools</artifactId> 45 <scope>runtime</scope> 46 <optional>true</optional> 47 </dependency> 48 <dependency> 49 <groupId>com.oracle.ojdbc</groupId> 50 <artifactId>ojdbc8</artifactId> 51 <scope>runtime</scope> 52 </dependency> 53 <dependency> 54 <groupId>mysql</groupId> 55 <artifactId>mysql-connector-java</artifactId> 56 <scope>runtime</scope> 57 </dependency> 58 <dependency> 59 <groupId>org.springframework.boot</groupId> 60 <artifactId>spring-boot-configuration-processor</artifactId> 61 <optional>true</optional> 62 </dependency> 63 <dependency> 64 <groupId>org.projectlombok</groupId> 65 <artifactId>lombok</artifactId> 66 <optional>true</optional> 67 </dependency> 68 <dependency> 69 <groupId>org.springframework.boot</groupId> 70 <artifactId>spring-boot-starter-test</artifactId> 71 <scope>test</scope> 72 <exclusions> 73 <exclusion> 74 <groupId>org.junit.vintage</groupId> 75 <artifactId>junit-vintage-engine</artifactId> 76 </exclusion> 77 </exclusions> 78 </dependency> 79 </dependencies> 80 81 <build> 82 <plugins> 83 <plugin> 84 <groupId>org.springframework.boot</groupId> 85 <artifactId>spring-boot-maven-plugin</artifactId> 86 </plugin> 87 </plugins> 88 </build> 89 90 </project>
3.了解以上可以做個demo進行一下簡單測試,不想做測試可以繼續看第二篇進行其他插件的集成
遇到的坑之一:
JRebel版本過舊不能與spring版本相匹配
1 2020-01-07 16:04:55 JRebel: ERROR Class 'org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry' could not be processed by org.zeroturnaround.javarebel.integration.spring.cbp.MappingRegistryCBP@sun.misc.Launcher$AppClassLoader@18
遇到的坑之二:忘記配置數據庫連接了,因為是個springweb集成了mybatis 所以不配置會報錯
配置文件入下application.yml
############################## 項目啟動信息配置 開始 ##############################
server:
port: 8080
# tomcat:
# port-header: HEAD,PUT,DELETE,OPTIONS,TRACE,COPY,SEARCH,PROPFIND
# min-spare-threads: 20
# max-threads: 500
# connection-timeout: 10000
############################## 項目啟動信息配置 結束 ##############################
############################## 數據庫配置 開始 ###################################
spring:
datasource:
url: jdbc:mysql://127.0.0.1:3306/signin?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false
username: root
password: 123
driver-class-name: com.mysql.cj.jdbc.Driver
############################## 數據庫配置 結束 ####################################
此時項目目錄如下:該注意的如圖紅色標記
啟動項目后訪問localhost:8080/hello 設置斷點去調試可知走了該方法,返回index.html頁面,為什么不用在return后加index文件后綴.html,與thymeleaf的模板引擎解析有關。