山東高端網(wǎng)站建設nba排名西部和東部
方式1:在線創(chuàng)建項目
https://start.spring.io/
環(huán)境準備
- (1)JDK 環(huán)境必須是 1.8 及以上,傳送門:jdk1.8.191 下載
- (2)后面要使用到 Maven 管理工具 3.2.5 及以上版本
- (3)開發(fā)工具建議使用 IDEA
方式2:IDEA創(chuàng)建
1.IDEA創(chuàng)建
創(chuàng)建之后,等待編譯完成
?過程時間很多??赡?0多分鐘也可能幾個小時
啟動:
啟動時報錯:
出現(xiàn)的錯誤No?MyBatis?mapper was found
解決1:啟動類頭加上忽略mapper配置
報這種錯的原因在于spring boot默認會加載org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration類,而DataSourceAutoConfiguration類使用了@Configuration注解向spring注入了dataSource bean。因為工程中沒有關于dataSource相關的配置信息,當spring創(chuàng)建dataSource bean因缺少相關的信息就會報錯。
如果我們用SpringBoot實現(xiàn)一個簡單的微服務,不需要數(shù)據(jù)庫,我們可以這樣解決:在application類加上注解:(exclude={})
//禁用數(shù)據(jù)庫自動配置,
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class,DataSourceTransactionManagerAutoConfiguration.class,HibernateJpaAutoConfiguration.class})
public class Demo17Application {public static void main(String[] args) {SpringApplication.run(Demo17Application.class, args);}}
解決2:啟動類頭加上mapper配置
配置服務器端口
application.properties
#配置端口
server.port=8088
新建Controller
新建一個Controller目錄,創(chuàng)建了一個類
package com.example.demo17.controller;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;@Controller
@RequestMapping("/hello")
public class HelloWorld {@RequestMapping("/hellowold")public String helloworld() {return "Hello Lain";}
}
調(diào)用一個Controller
創(chuàng)建好HelloWorld控制器之后,在瀏覽器:http://localhost:8088/hello/hellowold
SpringBoot 項目創(chuàng)建與運行成功~~~~?