文档章节

Spring Boot开发(一)-一个简单的Spring Boot工程

似是而非Sage
 似是而非Sage
发布于 2016/06/30 16:52
字数 656
阅读 600
收藏 2

0.开发前的准备

  • Spring Boot主页:http://projects.spring.io/spring-boot/

  • Gradle使用

1.简单的入门级的例子

  • Gradle配置

group 'org.ceecode'
version '1.0-SNAPSHOT'

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        //Spring Boot
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.5.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'spring-boot'

sourceCompatibility = 1.7

repositories {
    mavenCentral()
}

dependencies {
    testCompile("org.springframework.boot:spring-boot-starter-test")

    compile("org.springframework.boot:spring-boot-starter-web")
}
  • 核心代码-Controller
@Controller
@EnableAutoConfiguration
@RequestMapping("/")
public class TestApiController {

    @RequestMapping("test")
    @ResponseBody
    public String test() {
        return "OK";
    }

}
  • 核心代码-入口
@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(TestApiController.class, args);
    }

}

2.运行例子

    例子的运行很简单,直接执行Main方法即可.执行后的输入日志:

2016-06-30 16:35:46.900  INFO 47306 --- [           main] Application                              : Starting Application on XUEQI-MACdeMacBook-Pro.local with PID 47306 (started by xueqi in /Users/xueqi/Development/Resource/IDEA Java/springboot-project)
2016-06-30 16:35:46.912  INFO 47306 --- [           main] Application                              : No active profile set, falling back to default profiles: default
2016-06-30 16:35:47.094  INFO 47306 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7f416310: startup date [Thu Jun 30 16:35:47 CST 2016]; root of context hierarchy
2016-06-30 16:35:49.692  INFO 47306 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2016-06-30 16:35:49.724  INFO 47306 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2016-06-30 16:35:49.727  INFO 47306 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.0.33
2016-06-30 16:35:49.881  INFO 47306 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2016-06-30 16:35:49.881  INFO 47306 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2795 ms
2016-06-30 16:35:50.249  INFO 47306 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'dispatcherServlet' to [/]
2016-06-30 16:35:50.255  INFO 47306 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-06-30 16:35:50.255  INFO 47306 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-06-30 16:35:50.256  INFO 47306 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-06-30 16:35:50.256  INFO 47306 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'requestContextFilter' to: [/*]
2016-06-30 16:35:50.672  INFO 47306 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7f416310: startup date [Thu Jun 30 16:35:47 CST 2016]; root of context hierarchy
2016-06-30 16:35:50.763  INFO 47306 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/test]}" onto public java.lang.String controller.TestApiController.test()
2016-06-30 16:35:50.770  INFO 47306 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2016-06-30 16:35:50.772  INFO 47306 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2016-06-30 16:35:50.818  INFO 47306 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-06-30 16:35:50.819  INFO 47306 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-06-30 16:35:50.869  INFO 47306 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-06-30 16:35:51.134  INFO 47306 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2016-06-30 16:35:51.242  INFO 47306 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-06-30 16:35:51.250  INFO 47306 --- [           main] Application                              : Started Application in 5.137 seconds (JVM running for 6.094)
2016-06-30 16:36:00.261  INFO 47306 --- [       Thread-2] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7f416310: startup date [Thu Jun 30 16:35:47 CST 2016]; root of context hierarchy
2016-06-30 16:36:00.265  INFO 47306 --- [       Thread-2] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown

访问接口地址:

© 著作权归作者所有

共有 人打赏支持
似是而非Sage
粉丝 4
博文 11
码字总数 10369
作品 0
嘉定
后端工程师
私信 提问
Spring Boot HelloWorld 解析

开发环境 开发工具:IDEA 2017.2.2 链接: https://pan.baidu.com/s/1qxZLZtBR-Xr7JVkgmhZWzw 密码: wsqp 激活教程:http://idea.lanyus.com/ Spring Boot:2.0.3.RELEASE 参考文档:https://d......

爱编程的帅小伙
07/02
0
0
SpringBoot自定义starter

SpringBoot 提供了众多的starter简化我们开发,为了更好地使用这些starter,了解其原理是很重要的,今天就来自定义一个starter。 1,如何自定义 ①,我们首先要有一个意识,springboot自己适...

暗中观察
05/21
0
0
SpringBoot | 第一章:第一个SpringBoot应用

SpringBoot | 第一章:第一个SpringBoot应用 springboot简单介绍 概述 随着动态语言的流行(Ruby、Groovy、Scala、Node.js),Java的开发显得格外的笨重:繁多的配置、低下的开发效率、复杂的...

oKong
07/15
0
0
第一个SpringBoot示例

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

zq木偶人
07/19
0
0
SpringBoot|第一章:第一个SpringBoot 应用

springboot简单介绍 概述 随着动态语言的流行(Ruby、Groovy、Scala、Node.js),Java的开发显得格外的笨重:繁多的配置、低下的开发效率、复杂的部署流程以及第三方技术集成难度大。 在上述...

Java架构解析
08/18
0
0

没有更多内容

加载失败,请刷新页面

加载更多

storm 环境搭建

1.下载解压 下载地址:http://storm.apache.org/downloads.html

MrPei
7分钟前
0
0
Python Base - 读写文件,字符串拼接,单引号

字符转义 读写文件cvs 字符串拼接,替换 import csvcsv_file_name = 'cardbin.csv'# insert into `card_bin_code` (name_of, code_of, card_no_prefix, bank_code) values ('中国银行......

园领T
9分钟前
0
0
基于JQUERY BOOTSTRAP 最简单的loading遮罩层

<%--loading遮罩层--%><div class="modal fade" id="loadingModal" backdrop="static" keyboard="false">   <div style="width: 200px;height:20px; z-index: 20000; position: abs......

颖辉小居
9分钟前
0
0
springboot+kafka

1,首先springboot对kafka的支持也很好,同样是在配置文件中配置好参数,然后就可以直接使用。先说一下,很简单,,,不要怕 2,我用的依赖是 <dependency> <groupId>org.springframewor...

我真是小菜鸡
13分钟前
2
0
webservice动态客户端自我记录备份(spring boot)

动态客户端相比直接调用webservice的客户端代码要简单很多,但实际上很多工作是java自己替我们做掉了。简单记录一下内容,以备后续使用: pom文件只需要引入: <!-- CXF webservice --><de...

checkboxMan
19分钟前
0
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部