- 创建简单的springboot项目
- idea创建一个普通maven项目,打开pox.xml,添加springboot依赖配置
- 创建一个启动类
- 创建一个controller
- 就这么简单,现在可以启动了
- 现在我要模拟部署这个项目
...创建一个启动类org.springframework.boot spring-boot-starter-parent 1.5.9.RELEASE org.springframework.boot spring-boot-starter-web ... org.springframework.boot spring-boot-maven-plugin true
package com.xuexi;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class,args);
}
}
创建一个controller
package com.xuexi.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HelloController {
// 前端url直接访问 localhost:8080/hello (不用加项目名)
@ResponseBody
@RequestMapping("/hello")
public String hello(){
return "Hello World!";
}
}
就这么简单,现在可以启动了
1.运行App类里的main方法
2.看日志显示出以下信息就算启动成功了
... : Tomcat started on port(s): 8080 (http) ... : Started App in 1.144 seconds (JVM running for 2.043)
3.浏览器输入 http://localhost:8080/hello 页面会打印Hello World!
现在我要模拟部署这个项目1.在idea右边找到Maven - (项目) -Lifecycle - 鼠标双击package,等待日志打印完成,生成jar包
2.打完后jar包默认放在项目的target目录下,以项目名-版本号.jar命名,我的jar包名字叫spring-boot01-1.0-SNAPSHOT.jar
3.复制jar包到电脑D:盘,cmd进入D:盘,执行命令 java -jar spring-boot01-1.0-SNAPSHOT.jar
4.等项目启动完成后,就相当于部署完成,页面访问http://localhost:8080/hello一样会打印Hello World!



