1.创建一个Maven应用工程
2.在pom.xml添加SpringBoot Jar包依赖
<?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>cn.ultimate.springboot</groupId> <artifactId>cn.test.springboot</artifactId> <version>1.0-SNAPSHOT</version> <name>cn.test.springboot</name> <!-- 继承默认的springboot--> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.1.RELEASE</version> </parent> <!-- Web 应用程序依赖包 --> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> </project> |
3.在App.java中编写代码
@SpringBootApplication @RestController public class App { public static void main( String[] args ) { SpringApplication.run(App.class,args); } @RequestMapping("/") public String hello(){ return "Hello World"; } } |
4.运行App.java程序
在我们的控制台,将会看到类似如下的输出信息
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.0.1.RELEASE) ...... |