1、首先是pom.xml的一些依赖引用和插件:
4.0.0 org.example spring-boot-duing-02-configration1.0-SNAPSHOT org.springframework.boot spring-boot-starter-parent2.1.8.RELEASE org.springframework.boot spring-boot-starter-weborg.springframework.boot spring-boot-devtoolstrue org.springframework.boot spring-boot-configuration-processortrue org.springframework.boot spring-boot-maven-plugin2.5.6
2.打开入口类
@SpringBootApplication
public class Demo {
public static void main(String[] args) {
SpringApplication.run(Demo.class,args);
}
}
3.放入业务逻辑
@Controller
public class HelloController {
@RequestMapping("/hello")
@ResponseBody
public String hello(){
return "hello world";
}
}
4.注意,spring-boot默认加载与自己启动类同包下或者子包下的内容,如果在这之外写的代码,是不会 被加载进来,所以 会找不到。所以 一般把启动类拖到最外层(引用处:(9条消息) spring-boot项目搭建一(hello word)_青蛙的博客-CSDN博客)
例如我的Demo启动类和Controller业务逻辑类:
5.创建Resource文件夹下的banner.txt,可以设置启动时的图像,例如:
// _ooOoo_ // // o8888888o // // 88" . "88 // // (| ^_^ |) // // O = /O // // ____/`---'____ // // .' \| |// `. // // / \||| : |||// // // / _||||| -:- |||||- // // | | \ - /// | | // // | _| ''---/'' | | // // .-__ `-` ___/-. / // // ___`. .' /--.-- `. . ___ // // ."" '< `.____<|>_/___.' >'"". // // | | : `- `.;` _ /`;.`/ - ` : | | // // `-. _ __ /__ _/ .-` / / // // ========`-.____`-.________/___.-`____.-'======== // // `=---=' // // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // // 佛祖保佑 永不宕机 永无BUG //
运行得到效果:
6.热部署配置
修改代码后,idea自动运行更新程序,不用手动操作
1)引入依赖,上面pom.xml文件已给出
2)idea的setting设置,勾选Build project automatically
老版本有第三步快捷键勾选 compiler.automake.allow.when.app.running
新版本Ctrl+shift+Alt+/ 找不到选项,直接在setting中设置
勾选Build project automatically
勾选 compiler.automake.allow.when.app.running
7.打包插件
maven依赖在pom.xml已给出
点击package,可打包当前的项目



