微框架 - spring boot快速入门

7 篇文章 0 订阅

每次搭建项目可能是最浪费时间的一个环节,不管你是想做个什么东西,特别是要发布web环境,即使你讲tomcat或者jetty都集成在maven中,这一套下来可能在你脑海里划过的一些思绪早已无影无踪。今天发现了一个好用的spring的“微框架”: Spring Boot。

Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。

看一下搭建这么一个web环境的过程:

1.配置maven:

       <dependency>
	    <groupId>org.springframework.boot</groupId>
	    <artifactId>spring-boot-starter-web</artifactId>
	    <version>1.0.2.RELEASE</version>
	</dependency>
2.发布一个微服务:

package com.tiger.springboot;
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) {
        SpringApplication.run(SimpleController.class, args);
    }
}
然后就没有然后了,启动服务就可以通过浏览器访问项目了。

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.0.2.RELEASE)

2015-02-05 01:38:28.069  INFO 5872 --- [           main] com.tiger.springboot.SimpleController    : Starting SimpleController on tiger with PID 5872 (H:\workspace\springboot\target\classes started by Administrator in H:\workspace\springboot)
2015-02-05 01:38:28.109  INFO 5872 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@1dbdf42: startup date [Thu Feb 05 01:38:28 CST 2015]; root of context hierarchy
2015-02-05 01:38:29.037  INFO 5872 --- [           main] .t.TomcatEmbeddedServletContainerFactory : Server initialized with port: 8080
2015-02-05 01:38:29.213  INFO 5872 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2015-02-05 01:38:29.214  INFO 5872 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/7.0.52
2015-02-05 01:38:29.325  INFO 5872 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2015-02-05 01:38:29.325  INFO 5872 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1217 ms
2015-02-05 01:38:29.870  INFO 5872 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'dispatcherServlet' to [/]
2015-02-05 01:38:29.873  INFO 5872 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2015-02-05 01:38:30.074  INFO 5872 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2015-02-05 01:38:30.140  INFO 5872 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/hello],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.tiger.springboot.SimpleController.hello()
2015-02-05 01:38:30.158  INFO 5872 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2015-02-05 01:38:30.158  INFO 5872 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2015-02-05 01:38:30.289  INFO 5872 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2015-02-05 01:38:30.318  INFO 5872 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080/http
2015-02-05 01:38:30.319  INFO 5872 --- [           main] com.tiger.springboot.SimpleController    : Started SimpleController in 2.621 seconds (JVM running for 2.934)
从这个 大logo看的出spring boot这帮大神玩得还是挺开心的.其实是通过tomcat的8080端口发布的,但是这些你现在都不必去关心了。至于tomcat的一些高级配置还没有去研究,如ssl证书一类的,可能应该可以支持吧。不过到目前为止用这一套开做一些demo或者模块的快速开发应该是很不错的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值