第一次構建springboot項目
一、推薦使用Spring Initializr快速構建springboot
第一步:新建項目,jdk最好1.8以上,下一步
第二步:
Group : 組名(不用多說了吧!不行就默認)
Artifact:項目名稱
其他默認就行
第三步:選擇web,如下配置
構建完成
文件目錄如下
Boot1Application就是啓動類
再看一下pom
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.zzs</groupId>
<artifactId>boot1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>boot1</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
初次構建springboot需要下載依賴庫,可能等很長一段時間,如果等得時間長了,你可能需要以下配置
參考連接:阿里雲鏡像
到啓動類那邊啓動!看到spring 的logo 和8080端口就OK了
想要直接訪問會出現error,因爲我們還沒有做輸出
自己寫一個Controller類
@Controller
public class hellowordController {
@RequestMapping("/hello")
@ResponseBody
public String hello(){
return "hellowWorld";
}
}