码迷,mamicode.com
首页 > 编程语言 > 详细

SpringBoot 搭建

时间:2017-04-26 22:23:16      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:parent   art   lips   hello   log   static   ati   sys   system   

1、使用Eclipse 建立Maven项目(webapp OR quickstart)

2、配置Maven,如下:

 1  <parent>
 2     <groupId>org.springframework.boot</groupId>
 3     <artifactId>spring-boot-starter-parent</artifactId>
 4     <version>1.2.5.RELEASE</version>
 5     <relativePath/>
 6   </parent>
 7 
 8   <properties>
 9     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10     <java.version>1.8</java.version>
11   </properties>
12 
13   <dependencies>
14     <dependency>
15       <groupId>org.springframework.boot</groupId>
16       <artifactId>spring-boot-starter-web</artifactId>
17     </dependency>
18   </dependencies>
19 
20   <build>
21     <plugins>
22       <plugin>
23         <groupId>org.springframework.boot</groupId>
24         <artifactId>spring-boot-maven-plugin</artifactId>
25       </plugin>
26     </plugins>
27   </build>

3、建立启动Application

 1 package demo.web.application;
 2 import org.springframework.boot.SpringApplication;  
 3 import org.springframework.boot.autoconfigure.SpringBootApplication;
 4 import org.springframework.context.annotation.ComponentScan;
 5 
 6 @SpringBootApplication 
 7 @ComponentScan(basePackages={"demo.web.*"}) 
 8 public class Application {
 9     public static void main(String[] args) {  
10         SpringApplication.run(Application.class, args);  
11     }  
12 
13 }

4、编辑Controller

 1 package demo.web.controller;
 2 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;  
 3 import org.springframework.web.bind.annotation.PathVariable;  
 4 import org.springframework.web.bind.annotation.RequestMapping;  
 5 import org.springframework.web.bind.annotation.RestController;  
 6   
 7 @RestController  
 8 @EnableAutoConfiguration
 9 public class HelloController {
10     
11     @RequestMapping("/")  
12     String home() {  
13         System.out.println("ee");
14         return "Hello World!";  
15     }  
16       
17     @RequestMapping("/hello/{myName}")  
18     String index(@PathVariable String myName) {  
19         return "Hello "+myName+"!!!";  
20     }  
21 
22 }

5、通过application.properties对项目进行配置

server.port=9000  

项目文件布局如下:

技术分享

启动Application程序,即可访问网站。

技术分享

 

SpringBoot 搭建

标签:parent   art   lips   hello   log   static   ati   sys   system   

原文地址:http://www.cnblogs.com/learnMoreEveryday/p/6771354.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!