?
最近在搞一個專案,摒棄了公司老套的框架模式, 采用了springboot搭建新應用,看到如此簡潔的代碼 , 深受傭訓,趁周末閑余之時, 打開了b站,跟著動力節點的視頻學起了springboot
視瞥澩
https://www.bilibili.com/video/BV1XQ4y1m7ex
簡單粗暴的, 搭建個應用run起來 . 本文不介紹細節, 后續會深入了解springboot,剖析原始碼
一、搭建一個maven模塊工程
1、父工程
mvn archetype:generate -DgroupId=com.springboot.demo -DartifactId=demo -DarchetypeArtifactId=maven-archetype-site-simple -DinteractiveMode=false
2、子工程client端
mvn archetype:generate -DgroupId=com.springboot.demo -DartifactId=demo-client -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
3、子工程server端
mvn archetype:generate -DgroupId=com.springboot.demo -DartifactId=demo-web -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
二、springboot的引入
添加springboot 的父pom配置
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.0.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.3.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
要添加springboot構建的web 子工程, pom只需配置
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
pom加入這些配置后, 可以自動依賴內嵌的tomcat 和 spring-mvc了 , 從而支持了web開發
三、定義springboot的主類(啟動tomcat)
@RestController
@EnableAutoConfiguration
public class Application {
@RequestMapping("/")
public String index() {
return "hello, spring boot";
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
@EnableAutoConfiguration : 表明了這個類是springboot的主類, 可以看到啟動入口就是main函式了,趕緊跑下看看, 可以訪問 http://localhost:8080/ 可以看到頁面輸入
hello, spring boot
截止到這里,我們就完成了一個簡單的springboot工程搭建,
?
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/444315.html
標籤:Java
上一篇:阿里一面:ReadWriteLock 讀寫之間互斥嗎?我竟然答不上來。。
下一篇:Java的jstat命令使用詳解
