Spring Boot 之Hello Word

Spring Boot官网:http://projects.spring.io/spring-boot/

环境准备:maven 3.3.5、jdk8、Idea

1.创建maven项目工程

2.引入starters

 1 <parent>
 2     <groupId>org.springframework.boot</groupId>
 3     <artifactId>spring-boot-starter-parent</artifactId>
 4     <version>1.5.11.RELEASE</version>
 5 </parent>
 6 <dependencies>
 7     <dependency>
 8         <groupId>org.springframework.boot</groupId>
 9         <artifactId>spring-boot-starter-web</artifactId>
10     </dependency>
11 </dependencies>

3.创建主程序

1 @SpringBootApplication
2 public class HelloWorldMainApplication {
3 
4     public static void main(String[] args){
5         //Spring 应用启动起来
6         SpringApplication.run(HelloWorldMainApplication.class, args);
7     }
8 }

4.创建一个Controller

1 @Controller
2 public class HelloController {
3 
4     @RequestMapping("/hello")
5     @ResponseBody
6     public String hello(){
7         return "Hello Word!";
8     }
9 }

5.运行主方法,并在浏览器输入:localhost:8080/hello ,就会出现Hello Word!

6.也可以打包成jar包 进行部署

url:https://docs.spring.io/spring-boot/docs/1.5.11.RELEASE/reference/htmlsingle/#getting-started-first-application-executable-jar

这个插件,可以将应用打包成一个jar包 
1 <build>
2     <plugins>
3         <plugin>
4             <groupId>org.springframework.boot</groupId>
5             <artifactId>spring-boot-maven-plugin</artifactId>
6         </plugin>
7     </plugins>
8 </build>

 

posted @ 2018-04-08 22:42  Mr.Moon  阅读(255)  评论(0编辑  收藏  举报