1. 程式人生 > >SpringBoot簡易搭建

SpringBoot簡易搭建

1.建立maven工程

2.開啟pom檔案, 將以下配置拷貝過去

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

3.java檔案內啟動springboot, 並編寫一個測試方法來測試

/**
 * Hello world!
 *
 */
@SpringBootApplication
public class App 
{
    public static void main( String[] args )
    {
        SpringApplication.run(App.class, args);
    }
    
    @Controller
    public class TestController {
    	@RequestMapping("/hello")
    	@ResponseBody
    	public String hello() {
    		return "hello";
    	}
    }
}

4.開啟java檔案,右鍵==> Run As==> Java Application, 等待啟動完成, 瀏覽器測試顯示如下