热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

我的第一个springboot应用+maven依赖管理

第一步:使用Eclipse创建maven工程SpringBootFirst:工程目录如下第二步:编写依赖文件pom.xml<projectxmlns&

第一步:使用Eclipse创建maven工程SpringBootFirst:工程目录如下

我的第一个springboot应用+maven依赖管理

第二步:编写依赖文件pom.xml

<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.0modelVersion>
  <parent>
    <groupId>com.xzh.springbootgroupId>
    <artifactId>SpringBoot-parentartifactId>
    <version>0.0.1-SNAPSHOTversion>
  parent>
  <groupId>com.xzhgroupId>
  <artifactId>SpringBootFirstartifactId>
  <version>0.0.1-SNAPSHOTversion>
  <packaging>warpackaging>
  <name>SpringBootFirstname>
  <description>SpringBootFirst  for 20170717description>
  
  <dependencies>
    <dependency>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-webartifactId>
    dependency>
  dependencies>
project>

编写web控制器:SampleController

package me.hello;
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;

@Controller
@EnableAutoConfiguration
public class SampleController {
    @RequestMapping("/")
    @ResponseBody
    String home() 
    {
        return "Hello World!";
    }
    public static void main(String[] args) throws Exception {
        SpringApplication.run(SampleController.class, args);
    }
}


第三步:右击SpringBootFirst工程,选择如下图运行

 我的第一个springboot应用+maven依赖管理

运行结果如下:

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

2017-07-24 11:25:35.788  INFO 8760 --- [           main] me.hello.SampleController                : Starting SampleController on Lenovo-PC with PID 8760 (F:\eclipseworkspace\SpringBootFirst\target\classes started by hengliu in F:\eclipseworkspace\SpringBootFirst)
2017-07-24 11:25:35.791  INFO 8760 --- [           main] me.hello.SampleController                : No active profile set, falling back to default profiles: default
2017-07-24 11:25:35.849  INFO 8760 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@1e4a7dd4: startup date [Mon Jul 24 11:25:35 CST 2017]; root of context hierarchy
2017-07-24 11:25:38.608  INFO 8760 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-07-24 11:25:38.642  INFO 8760 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2017-07-24 11:25:38.643  INFO 8760 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.15
2017-07-24 11:25:38.849  INFO 8760 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2017-07-24 11:25:38.849  INFO 8760 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3010 ms
2017-07-24 11:25:39.071  INFO 8760 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2017-07-24 11:25:39.077  INFO 8760 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-07-24 11:25:39.078  INFO 8760 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-07-24 11:25:39.079  INFO 8760 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-07-24 11:25:39.079  INFO 8760 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2017-07-24 11:25:39.719  INFO 8760 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@1e4a7dd4: startup date [Mon Jul 24 11:25:35 CST 2017]; root of context hierarchy
2017-07-24 11:25:39.851  INFO 8760 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/]}" onto java.lang.String me.hello.SampleController.home()
2017-07-24 11:25:39.855  INFO 8760 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-07-24 11:25:39.856  INFO 8760 --- [           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)
2017-07-24 11:25:39.898  INFO 8760 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-07-24 11:25:39.899  INFO 8760 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-07-24 11:25:39.954  INFO 8760 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-07-24 11:25:40.144  INFO 8760 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2017-07-24 11:25:40.297  INFO 8760 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-07-24 11:25:40.304  INFO 8760 --- [           main] me.hello.SampleController                : Started SampleController in 5.157 seconds (JVM running for 6.183)
2017-07-24 11:26:36.857  INFO 8760 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2017-07-24 11:26:36.858  INFO 8760 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
2017-07-24 11:26:36.880  INFO 8760 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 22 ms

说明运行成功,启动了自带的Tomcat服务器,然后打开浏览器输入:http://localhost:8080/
运行结果如下图:

我的第一个springboot应用+maven依赖管理

 


推荐阅读
author-avatar
神马26688_463
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有