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