- springboot随笔之一:简易springboot项目编写
- springboot随笔之二:springboot中control实现
- springboot随笔之三:springboot整合spring-data-jpa(关系型数据库mysql)
- springboot随笔之四:springboot整合spring-data-jpa(nosql mogodb)
一、首先创建一个jar类型的maven项目,创建的结构如下:
如果创建的maven项目如果出现如下报错:
org.apache.maven.plugins:maven-resources-plugin:2.6
解决办法:https://blog.csdn.net/wmc_bk/article/details/82464749
二、让普通的jar类型maven变为sprintboot项目
1、参考官方文档 https://docs.spring.io/spring-boot/docs/2.2.4.RELEASE/reference/html/getting-started.html#getting-started
来配置pom
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>springboot_expample_01</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- Inherit defaults from Spring Boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
</parent>
<!-- Add typical dependencies for a web application -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<!-- Package as an executable jar -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
2、编写应用启动类
package springboot_expample_01;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication //表示该类springboot的启动类
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
三、运行MyApplication类(按照普通java带main函数的类启动程序即可)
运行结果如下,8080端口已监听
四、其他方式创建
1、Spring Tool Suite可以直接创建springboot简易项目
这个方式非常简单,但pom里面需要确认依赖。
不是如下依赖,该依赖不是一个web项目,启动类运行后不会有服务端口监听。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
而是如下依赖,该依赖是一个web项目,启动类运行后会有服务端口监听。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
2、springboot官网填充项目信息后直接在线创建,然后下载来用开发工具导入亦可以。