关于Spring Boot
这是官网描述的特点:
1.Create stand-alone Spring applications
创建独立的Spring应用
2.Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)
内嵌了Tomcat,Jetty或者Undertow,并且不需要部署
3.Provide opinionated 'starter' POMs to simplify your Maven configuration
提供'starter' POMs来简化Maven配置
4.Automatically configure Spring whenever possible
尽可能的自动配置Spring应用
5.Provide production-ready features such as metrics, health checks and externalized configuration
提供生产特征,比如指标,健壮检查和外部化配置
6.Absolutely no code generation and no requirement for XML configuration
绝对没有任何代码生成,并且不需要配置XML
创建并运行一个Demo项目
首先在Eclipse中创建一个简单的Maven项目,在pom.xml中添加Spring boot的依赖,
1
2
3
4
5
|
<
dependency
>
<
groupId
>org.springframework.boot</
groupId
>
<
artifactId
>spring-boot-starter-web</
artifactId
>
<
version
>${spring.boot.version}</
version
>
</
dependency
>
|
创建一个Controller:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
@RestController
@EnableAutoConfiguration
public
class
Controller {
@RequestMapping
(value=
"/"
)
public
String test(){
return
"hello world!"
;
}
public
static
void
main(String[] args){
SpringApplication.run(Controller.
class
,args);
}
}
|
现在直接运行这个Controller就可以启动项目:
现在直接访问http://localhost:8080/,可以看到项目已经运行起来。