快速搭建一个spring boot web项目
一,第一步,建立spring boot项目,
两种方法:
1,使用spring boot tool工具快速生成spring boot项目
2.创建一个简单的maven 项目,在pom.xml里面添加:
添加父项目:
org.springframework.boot spring-boot-starter-parent 2.1.3.RELEASE
添加依赖:
org.springframework.boot spring-boot-starter
添加构建插件:
org.springframework.boot spring-boot-maven-plugin
在入口类上添加@SpringBootApplication注解,在main方法里面如下启动spring boot:
public static void main(String[] args) { SpringApplication.run(DbclientApplication.class, args); }
二,第二步,添加web,在pom.xml中添加依赖:
org.springframework.boot spring-boot-starter-web
三,第三步,设置静态文件位置及配置;SpringBoot默认了静态文件的位置src/main/resources下的static目录;
1.在src/main/resources下面的创建static文件夹,默认会访问里面的index.html文件。
2,在src/main/resources下面application.properties中添加下面配置端口:
# 端口 server.port=8004