文档章节

Spring-boot学习

一声叹息
 一声叹息
发布于 2016/10/26 20:22
字数 759
阅读 91
收藏 0

首先用IDEA新建一个maven工程

选择quickStart,项目新建完成后添加依赖,pom文件是这样的

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.chen.demo</groupId>
  <artifactId>desktop</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.1.RELEASE</version>
  </parent>
  <name>desktop</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
  </dependencies>
</project>

依赖下载完成后我们新建一个App.java文件,写一个HelloWorld测试项目搭建是否成功

package com.chen.demo;

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.ResponseBody;

/**
 * Hello world!
 *
 */
@Controller
@EnableAutoConfiguration
public class App 
{
    @RequestMapping("/")
    @ResponseBody
    public String home() {
        return "HelloWorld";
    }
    public static void main( String[] args )
    {
        SpringApplication.run(App.class, args);
    }
}

运行app,可以看到

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

2016-10-26 20:06:28.810  INFO 9856 --- [           main] com.chen.demo.App                        : Starting App on 2012-20160604HW with PID 9856 (D:\code\desktop\target\classes started by Administrator in D:\code\desktop)
2016-10-26 20:06:28.813  INFO 9856 --- [           main] com.chen.demo.App                        : No active profile set, falling back to default profiles: default
2016-10-26 20:06:28.894  INFO 9856 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@21de60b4: startup date [Wed Oct 26 20:06:28 CST 2016]; root of context hierarchy
2016-10-26 20:06:32.319  INFO 9856 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2016-10-26 20:06:32.337  INFO 9856 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2016-10-26 20:06:32.339  INFO 9856 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.5
2016-10-26 20:06:32.525  INFO 9856 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2016-10-26 20:06:32.526  INFO 9856 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3638 ms
2016-10-26 20:06:32.921  INFO 9856 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2016-10-26 20:06:33.084  INFO 9856 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-10-26 20:06:33.085  INFO 9856 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-10-26 20:06:33.085  INFO 9856 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-10-26 20:06:33.094  INFO 9856 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2016-10-26 20:06:36.062  INFO 9856 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@21de60b4: startup date [Wed Oct 26 20:06:28 CST 2016]; root of context hierarchy
2016-10-26 20:06:38.770  INFO 9856 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/]}" onto public java.lang.String com.chen.demo.App.home()
2016-10-26 20:06:38.774  INFO 9856 --- [           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-10-26 20:06:38.775  INFO 9856 --- [           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-10-26 20:06:38.850  INFO 9856 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-10-26 20:06:38.850  INFO 9856 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-10-26 20:06:39.063  INFO 9856 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-10-26 20:06:39.307  INFO 9856 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2016-10-26 20:06:39.408  INFO 9856 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-10-26 20:06:39.414  INFO 9856 --- [           main] com.chen.demo.App                        : Started App in 11.809 seconds (JVM running for 13.15)
2016-10-26 20:07:15.895  INFO 9856 --- [nio-8080-exec-1] o.apache.tomcat.util.http.parser.Cookie  : A cookie header was received [1476964939,1477056698; Webstorm-df1b66bd=cc381a18-02ee-47a3-ab17-955c593fdcfc] that contained an invalid cookie. That cookie will be ignored.Note: further occurrences of this error will be logged at DEBUG level.
2016-10-26 20:07:15.901  INFO 9856 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2016-10-26 20:07:15.902  INFO 9856 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
2016-10-26 20:07:15.939  INFO 9856 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 37 ms

表示运行成功,这样我们就可以通过localhost://8080来访问了

 

© 著作权归作者所有

上一篇: beego之创建项目
一声叹息
粉丝 0
博文 4
码字总数 1326
作品 0
西安
程序员
私信 提问
spring boot框架学习5-spring boot的web开发(1)

本章节主要内容: 通过前面的学习,我们了解并快速完成了spring boot第一个应用。spring boot企业级框架,那么spring boot怎么读取静态资源?如js文件夹,css文件以及png/jpg图片呢?怎么自定...

凯哥java
2017/11/01
0
0
spring boot框架学习4-spring boot核心(3)

本节主要: 1:spring boot 为我们提供的 starter pom 都有哪些 2:怎么添加xml配置文件 3:日志相关 本文是《凯哥陪你学系列-框架学习之spring boot框架学习》中第四篇 spring boot框架学习...

凯哥java
2017/10/31
0
0
spring boot框架学习6-spring boot的web开发(2)

本章节主要内容: 通过前面的学习,我们了解并快速完成了spring boot第一个应用。spring boot企业级框架,那么spring boot怎么读取静态资源?如js文件夹,css文件以及png/jpg图片呢?怎么自定...

凯哥java
2017/11/06
0
0
Github 上 Star 最多的个人 Spring Boot 开源学习项目

2016年,在一次技术调研的过程中认识到了 Spring Boot ,试用之后便一发不可收拾的爱上它。为了防止学习之后忘记,就在网上连载了 Spring Boot 系列文章,没想到这一开始便与 Spring Boot 深...

ityouknow
02/28
0
0
spring boot框架学习2-spring boot核心(1)

本节主要: 1:解析spring boot入口和@SpringBootApplication源码详解 SpringBootApplication包含: @SpringBootConfiguration @ComponentScan @EnableAutoConfiguration 本文是《凯哥陪你学......

凯哥java
2017/10/27
0
0

没有更多内容

加载失败,请刷新页面

加载更多

我的程序人生——三年开发的思考,阿里朋友给我总结的“Java架构师技术栈”

想写这篇文章已经很久了,本来计划在3月份,也就是刚好满3年的时候写的,但是因为各种各样的原因推到了现在才开始码字。 小感慨 三年是一段很长的时间,它足够让你从高中毕业进入大学,也能让...

我最喜欢三大框架
13分钟前
0
0
ElasticSearch获取索引信息

检查集群的健康情况 GET /_cat/health?v green:每个索引的primary shard和replica shard都是active状态的 yellow:每个索引的primary shard都是active状态的,但是部分replica shard不是act...

水木星辰
15分钟前
0
0
Cesium中级教程6 - 3D Models 三维模型

Cesium中文网:http://cesiumcn.org/ | 国内快速访问:http://cesium.coinidea.com/ 3D Models 三维模型 本教程将教您如何通过Primitive API转换、加载和使用Cesium中的三维模型。如果你是C...

Cesium中文网
17分钟前
0
0
Elasticsearch简单学习1-用白话文解释原理

由于Elasticsearch在工作中用的越来越多,平时是边学边用,很少记录,读到一些很好的文章时间久了就忘记了。 所以,在此记录一下,希望对更多人的学习有帮助,知识在于分享! ==============...

wind2012
24分钟前
0
0
Spring面试题部分总结【慨念】

什么是Spring? spring是一个企业级应用的开源开发框架,主要用来开发java应用,spring框架目标就是简化企业级应用开发。 Spring用到了那些设计模式? spring里面用到了大量的设计模式,这里...

薛小二
25分钟前
4
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部