1.通过spring starter project 创建项目,选中web,自己创建个controller 做个示例:
package com.example.demo.controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping("/test/{name}")
@ResponseBody
public String index(@PathVariable String name){
return "hello world" +name;
}
}
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
2.eclipse mars 打包过程:
run as 下面:
maven clean
maven install
打包之后的文件在工程目录的target目录 SbootTest.jar
3.使用java的原生命令执行生成的jar文件
java -jar d:/SbootTest.jar --server.port=8888 即可
窗口关闭 项目停止运行。