通过创建Maven项目
1.创建maven项目,导入一些依赖
<?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>com.HSY</groupId>
<artifactId>Springboot_QuickStart</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<!-- web支持,SpringMVC, Servlet支持等 -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<!-- 打包成一个可执行的jar包-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
2.创建com.HSY包,包下创建springboot主类。运行该类的main方法,可以替代开启Tomcat的功能。
@SpringBootApplication
public class helloWordld
{
public static void main(String[] args)
{
SpringApplication.run(helloWordld.class, args);
}
}
3.编写一个controller进行测试
@Controller
public class HelloController
{
@RequestMapping("/hello")
@ResponseBody
public String hello()
{
return "hello";
}
}