選擇create New project
選擇maven,一般不需要模闆,如果你熟悉或者有自己經常使用的模闆可以選擇。
相當說填寫包名和項目名差不多
選擇項目路徑
finish
等待建構出一個空項目
建立包和application類
圖檔描述
Application要放在外層,否則無法掃描子包裡的東西。也就是它要在其他包的外層。這樣子才可以掃描到。
package net.sunofbeaches;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class BlogApplication {
public static void main(String[] args) {
SpringApplication.run(BlogApplication.class, args);
}
}
編寫配置檔案
配置内容包含很多,資料庫呀,端口呀,服務名稱,消息隊列…這裡我們先隻配置端口和名稱,其他的我們用到再進行配置。
在resources目錄下,建立application.yml檔案
spring:
application:
name: 檔案名
server:
port: 8080
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<groupId>net.sunofbeach.blog</groupId>
<artifactId>sob-blog-system</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>sob-blog</name>
<url>https://www.sunofbeach.net</url>
<inceptionYear>2020-Now</inceptionYear>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<finalName>sob-blog-1.0.0</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>net.sunofbeaches.BlogApplication</mainClass>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
</build>
</project>
看到提示的運作端口,就建立好項目了。