大致步驟
創建Maven工程
引入依賴
提供啟動類
詳細教程
創建Maven工程
修改pom.xml文件
添加父節點
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.5.3</version></parent>
添加springboot依賴
<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency></dependencies>
添加鏡像
<!-- 配置阿里云倉庫 --><repositories><repository><id>aliyun-repos</id><url>https://maven.aliyun.com/repository/public</url><releases><enabled>true</enabled></releases><snapshots><enabled>false</enabled></snapshots></repository></repositories><pluginRepositories><pluginRepository><id>aliyun-repos</id><url>https://maven.aliyun.com/repository/public</url><releases><enabled>true</enabled></releases><snapshots><enabled>false</enabled></snapshots></pluginRepository></pluginRepositories>
刷新
修改啟動類
@SpringBootApplication
public class SpringBootCreateManualApplication
{public static void main( String[] args ){SpringApplication.run(SpringBootCreateManualApplication.class,args);}
}
添加資源文件
添加配置文件
application.properties
添加簡單示例
package com.zwh.Controller;import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class HelloController {@RequestMapping("/hello")public String Hello(){return "Hello World~~~~~~~";}
}
使用的java24需要消除警告
--enable-native-access=ALL-UNNAMED--add-opens java.base/java.lang=ALL-UNNAMED
運行
查看端口
?查看結果
http://127.0.0.1:8080/hello