spring boot初探

又被领导鄙视了,说让先把程序跑起来,再去研究深层次的东西。。

我又一次没有学会走就要开始跑了。。说干就干

eclipse mars下载

新建maven project

加依赖

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.0.2.RELEASE</version>
</dependency>

等待maven帮忙下载jar包吧,太贴心!

新建一个control类

package com.mars.testweb.mavenTest;
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
@EnableAutoConfiguration
public class SimpleController {

@RequestMapping(value ="/hello", method = RequestMethod.GET)
@ResponseBody
public String hello(){
return "hello world";
}
public static void main(String[] args) {
// TODO Auto-generated method stub
SpringApplication.run(SimpleController.class, args);
}

}

右键,run as java Application

浏览器访问http://localhost:8080/hello

出现helloWord了~

spring boot真的就这么简单么,其实人家帮你屏蔽了很多细节,只需要关心业务逻辑实现,这固然是好的。

but,要是这么3分钟就能build好环境,傻瓜不都能写代码了么?

看看maven帮我们下载了哪些包呢?

从下往上看,有spring的基本包,含MVC,还有tomcat的jar包,以后不用安装tomcat也能跑web应用(赞),以及spring-boot的包。

虽然这么配置很简单,但是最好还是从头到尾配置一边,这样对spring框架才能有个全面的认识,当然,俺正在看spring的源码分析,稍后奉上,敬请期待。

posted @ 2016-06-07 23:58  谷子弟  阅读(255)  评论(0编辑  收藏  举报