SpringBoot官网: https://spring.io/projects/spring-boot
SpringBoot官方文档: https://docs.spring.io/spring-boot/docs/
- Java 8
- Maven 3.3+
- IntelliJ IDEA 2019.1.2
打开你的Maven安装目录下的setting.xml文件
可以打开IDEA的Settings查看安装目录
在setting.xml文件添加以下内容
3.创建工程nexus-aliyun central Nexus aliyun http://maven.aliyun.com/nexus/content/groups/public jdk-1.8 true 1.8 1.8 1.8 1.8
1.什么都不要勾选, 直接Next
2.给项目取个名字
3.Finish
4.创建成功
修改pom.xml文件, 内容如下
2.添加配置文件4.0.0 com.limi springboot-test1 1.0-SNAPSHOT jar org.springframework.boot spring-boot-starter-parent 2.3.4.RELEASE org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-maven-plugin
在resources目录下创建application.properties文件
application.properties
# 设置端口号,如果不设置,默认是8080 server.port=80813.创建java类
1.启动类MainApplication
package com.limi;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MainApplication {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class, args);
}
}
2.控制器类HelloController
package com.limi.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HelloController {
@GetMapping("/hello")
@ResponseBody
public String hello(){
return "Hello World!";
}
}
5.项目运行
1.直接点击启动类MainApplication里main方法旁边的小箭头就可以启动项目
2.打开浏览器进行访问,地址http://localhost:8081/hello
我们可以把项目打成jar包, 然后运行jar包
1.点击右侧的Maven按钮
2.在IDEA的Maven插件上依次点击(双击或者点绿色小箭头)运行 clean 、package,把helloworld工程项目的打包成jar包
clean
package
可以看到生成了springboot-test1-1.0-SNAPSHOT.jar文件
3.我们使用命令行运行它
打开该文件所在目录,在cmd中输入java -jar springboot-test1-1.0-SNAPSHOT.jar运行
可以看到在浏览器中可以访问,地址http://localhost:8081/hello
提示:关闭项目请按ctrl+c或者直接把cmd窗口关闭



