sprint boot 手动快速创建web应用

Posted い哎哟喂〤

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sprint boot 手动快速创建web应用相关的知识,希望对你有一定的参考价值。

1.打开Eclipse新建maven项目

 

 

 

 

 

 2.导入maven依赖

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

3.项目新建完成

 

 4.new package and new class

 

 5.copy示例:https://github.com/spring-projects/spring-boot

package xiaobing.springboot.controller;

import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.web.bind.annotation.*;

@RestController
@SpringBootApplication
public class Example {

    @RequestMapping("/")
    String home() {
        return "Hello World!";
    }

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

}

6.启动项目

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

2019-11-02 23:36:46.301  INFO 6576 --- [           main] xiaobing.springboot.controller.Example   : Starting Example on PC-20190411SFOQ with PID 6576 (D:\\Eclipse_workspace_springboot\\xiaobing.springboot\\target\\classes started by Administrator in D:\\Eclipse_workspace_springboot\\xiaobing.springboot)
2019-11-02 23:36:46.316  INFO 6576 --- [           main] xiaobing.springboot.controller.Example   : No active profile set, falling back to default profiles: default
2019-11-02 23:36:46.868  INFO 6576 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@1d548a08: startup date [Sat Nov 02 23:36:46 CST 2019]; root of context hierarchy
2019-11-02 23:36:57.008  INFO 6576 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-11-02 23:36:57.124  INFO 6576 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-11-02 23:36:57.126  INFO 6576 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.29
2019-11-02 23:36:57.172  INFO 6576 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\\Program Files\\Java\\jre1.8.0_211\\bin;C:\\Windows\\Sun\\Java\\bin;C:\\Windows\\system32;C:\\Windows;C:/Program Files/Java/jre1.8.0_211/bin/server;C:/Program Files/Java/jre1.8.0_211/bin;C:/Program Files/Java/jre1.8.0_211/lib/amd64;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\Java\\jdk1.8.0_211\\bin;C:\\Program Files\\Java\\jdk1.8.0_211\\jre\\bin;C:\\Program Files\\VisualSVN Server\\bin;D:\\TortoiseSVN\\bin;C:\\Program Files (x86)\\Tesseract-OCR;D:\\apache-maven-3.6.0\\apache-maven-3.6.0\\bin;D:\\allure\\allure-2.12.1\\bin;D:\\android-sdk-windows-appium\\platform-tools;D:\\android-sdk-windows-appium\\tools;;D:\\eclipse\\eclipse;;.]
2019-11-02 23:36:58.428  INFO 6576 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-11-02 23:36:58.429  INFO 6576 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 11571 ms
2019-11-02 23:36:58.932  INFO 6576 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2019-11-02 23:36:58.949  INFO 6576 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: \'characterEncodingFilter\' to: [/*]
2019-11-02 23:36:58.950  INFO 6576 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: \'hiddenHttpMethodFilter\' to: [/*]
2019-11-02 23:36:58.951  INFO 6576 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: \'httpPutFormContentFilter\' to: [/*]
2019-11-02 23:36:58.951  INFO 6576 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: \'requestContextFilter\' to: [/*]
2019-11-02 23:36:59.377  INFO 6576 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-11-02 23:37:00.238  INFO 6576 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@1d548a08: startup date [Sat Nov 02 23:36:46 CST 2019]; root of context hierarchy
2019-11-02 23:37:00.541  INFO 6576 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/]}" onto java.lang.String xiaobing.springboot.controller.Example.home()
2019-11-02 23:37:00.558  INFO 6576 --- [           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.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2019-11-02 23:37:00.561  INFO 6576 --- [           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.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2019-11-02 23:37:00.754  INFO 6576 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-11-02 23:37:00.755  INFO 6576 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-11-02 23:37:01.504  INFO 6576 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2019-11-02 23:37:01.772  INFO 6576 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path \'\'
2019-11-02 23:37:01.788  INFO 6576 --- [           main] xiaobing.springboot.controller.Example   : Started Example in 17.112 seconds (JVM running for 18.461)

7.访问项目

2019-11-02 23:41:20.516  INFO 6576 --- [nio-8080-exec-3] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet \'dispatcherServlet\'
2019-11-02 23:41:20.517  INFO 6576 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet        : FrameworkServlet \'dispatcherServlet\': initialization started
2019-11-02 23:41:20.572  INFO 6576 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet        : FrameworkServlet \'dispatcherServlet\': initialization completed in 55 ms

 

 

 

 

 

 

 

 

 

 

以上是关于sprint boot 手动快速创建web应用的主要内容,如果未能解决你的问题,请参考以下文章

Spring Boot2(002):手动创建第1个SpringBoot2简单应用——“HelloWorld” web 工程

用Spring Boot零配置快速创建web项目

Spring Boot 成长之路 快速上手

使用向导快速创建spring boot应用

Spring Boot 的 Web 应用程序开发

Sprint Boot如何基于Redis发布订阅实现异步消息系统的同步调用?