Spring-boot 第一次成功运行

以下是我的一些本机配置信息

IDE编辑环境:

Spring Tool Suite(STS)
下载网站:https://spring.io/tools/sts/all/

java运行环境:

java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

最好为JDK 1.8以上

Maven版本信息

Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-25T03:49:05+08:00)
Maven home: D:\Java Framework tools\apache-maven-3.5.3\bin\..
Java version: 1.8.0_131, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_131\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

参考手册:

https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/

实验步骤

  1. STS下创建java Application
  2. 创建目录结构:
     src/main/java/Example.java
  1. 粘贴XML代码
  2. 将pom文件粘贴到项目根目录(必须这样做,否则会出下如下错误信息)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.751 s
[INFO] Finished at: 2018-03-21T22:41:59+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] No plugin found for prefix 'boot' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\Users\onesl\.m2\repository), spring-snapshots (https://repo.spring.io/snapshot), spring-milestones (https://repo.spring.io/milestone), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
  1. 命令行下运行:mvn spring -boot:run
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< com.example:myproject >------------------------
[INFO] Building myproject 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:2.0.1.BUILD-SNAPSHOT:run (default-cli) > test-compile @ myproject >>>
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ myproject ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\workbunch\Spring Workbunch\Sboot02\src\main\resources
[INFO] skip non existing resourceDirectory D:\workbunch\Spring Workbunch\Sboot02\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ myproject ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\workbunch\Spring Workbunch\Sboot02\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:testResources (default-testResources) @ myproject ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\workbunch\Spring Workbunch\Sboot02\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ myproject ---
[INFO] No sources to compile
[INFO]
[INFO] <<< spring-boot-maven-plugin:2.0.1.BUILD-SNAPSHOT:run (default-cli) < test-compile @ myproject <<<
[INFO]
[INFO]
[INFO] --- spring-boot-maven-plugin:2.0.1.BUILD-SNAPSHOT:run (default-cli) @ myproject ---

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

2018-03-21 23:11:03.295  INFO 5080 --- [           main] main.java.Example                        : Starting Example on DESKTOP-UVHA77M with PID 5080 (started by onesl in D:\workbunch\Spring Workbunch\Sboot02)
2018-03-21 23:11:03.341  INFO 5080 --- [           main] main.java.Example                        : No active profile set, falling back to default profiles: default
2018-03-21 23:11:03.461  INFO 5080 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@b96473c: startup date [Wed Mar 21 23:11:03 CST 2018]; root of context hierarchy
2018-03-21 23:11:06.373  INFO 5080 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2018-03-21 23:11:06.497  INFO 5080 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-03-21 23:11:06.499  INFO 5080 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.29
2018-03-21 23:11:06.551  INFO 5080 --- [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\jdk1.8.0_131\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\130\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\;D:\MATLAB\matlab install location\runtime\win64;D:\MATLAB\matlab install location\bin;D:\MATLAB\matlab install location\polyspace\bin;C:\Program Files\dotnet\;C:\Program Files\Java\jdk1.8.0_131\bin;D:\tomcat version 7\apache-tomcat-7.0.82\bin;C:\Users\onesl\Desktop;C:\Users\onesl\AppData\Local\Microsoft\WindowsApps;D:\AAA-ONESLIDEICYWATER GLEANINGS\apache-ant-1.10.1-bin\apache-ant-1.10.1\bin;D:\Java Framework tools\apache-maven-3.5.3\bin;;.]
2018-03-21 23:11:06.890  INFO 5080 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-03-21 23:11:06.892  INFO 5080 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3435 ms
2018-03-21 23:11:07.068  INFO 5080 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-03-21 23:11:07.076  INFO 5080 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-03-21 23:11:07.079  INFO 5080 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-03-21 23:11:07.080  INFO 5080 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-03-21 23:11:07.083  INFO 5080 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-03-21 23:11:07.419  INFO 5080 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-21 23:11:07.613  INFO 5080 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@b96473c: startup date [Wed Mar 21 23:11:03 CST 2018]; root of context hierarchy
2018-03-21 23:11:07.750  INFO 5080 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/]}" onto java.lang.String main.java.Example.home()
2018-03-21 23:11:07.763  INFO 5080 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[application/xml || text/xml || application/json || application/*+xml || application/*+json]}" onto public org.springframework.http.ResponseEntity> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorStructured(javax.servlet.http.HttpServletRequest)
2018-03-21 23:11:07.767  INFO 5080 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorText(javax.servlet.http.HttpServletRequest)
2018-03-21 23:11:07.771  INFO 5080 --- [           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)
2018-03-21 23:11:07.811  INFO 5080 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-21 23:11:07.813  INFO 5080 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-21 23:11:08.122  INFO 5080 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-03-21 23:11:08.248  INFO 5080 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2018-03-21 23:11:08.256  INFO 5080 --- [           main] main.java.Example                        : Started Example in 5.854 seconds (JVM running for 12.658)
2018-03-21 23:11:52.994  INFO 5080 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2018-03-21 23:11:52.995  INFO 5080 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
2018-03-21 23:11:53.025  INFO 5080 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 29 ms

6.打开localhost,发现成功出现:
Spring-boot 第一次成功运行_第1张图片

你可能感兴趣的:(Java)