您的位置:首页 > 编程语言 > Java开发

Spring Boot初探

2016-04-25 12:20 507 查看
在一些开源项目的介绍上看到过很多次的spring
boot字眼,可一直没具体去看过,今天先简单上手跑通一下流程 :p回首我们以前使用Spring框架的时候,我们需要首先在(如果你使用Maven的话)pom文件中增加对相关的的依赖(使用gradle来构建的话基本也一样)然后新建Spring相关的xml文件,而且往往那些xml文件还不会少。然后继续使用tomcat或者jetty作为容器来运行这个工程。基本上每次创建一个新的项目都是这么一个流程,而我们有时候仅仅想快速的创建一个Spring
web工程来测试一些东西,或者是希望能节省时间springmvc4 mybatis 整合 框架源码 bootstrap html5下载地址 。现在我们使用Spring
Boot就可以快速的做到这些了。 1.创建一个Maven工程,然后我们在pom.xml文件中加入依赖:
<dependency>

<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.0.2.RELEASE</version></dependency>
2.写一个controller来处理请求:
package springboot.wiki.melon.springboottest;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.ResponseBody;@Controller@EnableAutoConfigurationpublic class FirstController {	@ResponseBody
@RequestMapping(value = "hello", method = { RequestMethod.POST,
RequestMethod.GET })	public String hello() {		return "Hello Melon! Hello spring boot !";
}	public static void main(String[] args) {
SpringApplication.run(FirstController.class, args);
}

}
3.Run!
然后访问 localhost:8080/hello,就能看到controller返回的内容了, 这个过程是不是非常快速简单 :p
. ____ _ __ _ _ /\\
/ ___'_ __ _ _(_)_ __ __ _ \ \ \ \(
( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/
___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ ::
Spring Boot :: (v1.0.2.RELEASE) --EOF--
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Spring Boot