conf/setting.xml:选择阿里云快一点
2、系统要求 二、helloWorldnexus-aliyun central Nexus aliyun http://maven.aliyun.com/nexus/content/groups/public jdk-1.8 true1.8 1.8 1.8 1.8
官方文档:https://spring.io/projects/spring-boot#learn
1、创建maven项目 1.1、引入依赖2、创建主程序org.springframework.boot spring-boot-starter-parent 2.5.4 org.springframework.boot spring-boot-starter-web
package com.boot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
//@SpringBootConfiguration
//@EnableAutoConfiguration
//@ComponentScan("com.boot")
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class,args);
}
}
3、编写业务
package com.boot.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.";
}
}
4、测试
直接运行main方法,
然后在浏览器中输入:http://localhost:8080/hello
5、题外话在springboot中咱们再也不用配置海量的配置文件,仅仅只需要创建一个application.properties文件就够了
需要改什么都可以在里面改
例如如果要修改端口号的话:
server.port=8888三、创建可执行的jar 1、添加插件
要创建可执行jar,我们需要将SpringBootMaven插件添加到pom.xml中。要执行此操作,请在dependencies部分下方插入以下行:
2、打包org.springframework.boot spring-boot-maven-plugin
也可以在输入命令:mvn package
成功结果:
打包的文件会放在target目录下
然后再cmd中运行,必须在同级目录下
3、注意点取消掉cmd的快速编辑模式:因为程序没运行好时,你点击窗口,程序可能会终止



