使用 Idea 创建 Maven 项目,添加 Spring Boot 依赖
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>shizidada.github.io</groupId>
<artifactId>moose</artifactId>
<version>1.0-SNAPSHOT</version>
<name>moose</name>
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<spring-boot.version>2.3.2.RELEASE</spring-boot.version>
<rocketmq.version>4.6.0</rocketmq.version>
<rocketmq.starter.version>2.1.0</rocketmq.starter.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!--> spring boot web 依赖</--->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--> spring boot 配置依赖</--->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.moose.MooseOperatorApplication</mainClass>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
</project>
创建 Springboot 启动类
@SpringBootApplication
public class MooseOperatorApplication {
public static void main(String[] args) {
SpringApplication.run(MooseOperatorApplication.class, args);
}
}
创建控制器
@RestController
public class IndexController {
@GetMapping("/")
public String index() {
return "Hello Spring Boot";
}
}
运行启动类 MooseOperatorApplication ;
springboot 项目默认运行端口为 8080,可以使用浏览器访问 http://localhost:8080 会看到 "Hello Spring Boot"
;
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.2.RELEASE)
....
2020-10-13 16:35:16.967 INFO 5696 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
关注公众号 「全栈技术部」
,不断学习更多有趣的技术知识。
![](https://i-blog.csdnimg.cn/blog_migrate/d835ddb4a4593912ac48f06c99475c24.jpeg)