springboot初探

系统要求:

  1. jdk7+(推荐jdk8)

  2. maven 3

  3. eclipse或其他编辑器

用eclipse创建一个maven项目(quick-start).

编写pom.xml

<?xml version=”1.0” encoding=”UTF-8”?>


4.0.0
com.example
myproject
0.0.1-SNAPSHOT

org.springframework.boot
spring-boot-starter-parent
1.3.0.BUILD-SNAPSHOT



org.springframework.boot
spring-boot-starter-web






spring-snapshots
http://repo.spring.io/snapshot

true



spring-milestones
http://repo.spring.io/milestone




spring-snapshots
http://repo.spring.io/snapshot


spring-milestones
http://repo.spring.io/milestone


创建source folder, src/main/java( 如有则忽略)

创建Example.java, 内容如下:

import org.springframework.boot.;
import org.springframework.boot.autoconfigure.
;
import org.springframework.stereotype.;
import org.springframework.web.bind.annotation.
;

@RestController
@EnableAutoConfiguration
public class Example {
@RequestMapping(“/“)
String home() {
return “Hello World!”;
}

public static void main(String\[\] args) throws Exception {
    SpringApplication.run(Example.class, args);
}

}

注意项目依赖的jre选择jre7或jre8.

项目目录结构如下:

运行Example的main方法,输出如下:

浏览器打开http://localhost:8080, 页面内容输出 “Hello World!”

本文实例参考 《spring-boot-reference-guide》一文

0%