第一篇:SpringBoot 2.x 构建工程

  1. 云栖社区>
  2. 博客>
  3. 正文

第一篇:SpringBoot 2.x 构建工程

gabriel丶 2018-10-08 14:41:00 浏览530
展开阅读全文

简介

一直以来都想写点关于springboot的东西,每次遇到的问题又记不住,本次的记录也是拾人牙慧,写一点关于自己的理解。
SpringBoot关于它在官网上的介绍是这样的

img_3394344afdcc9ffdfeff26bf0821b8a2.png
image.png

一个基于Spring可以轻松创建的独立的,生产级别的应用,让你可以 “只管运行”

官方的解释不是重点,我们只需要去关注SpringBoot是如何做到只管运行

在这里使用官方的springio构建项目的方式以及eclipse的springboot插件的构建方式,我就说下关于idea的搭建方式,其余的方式这里就不再赘述了,想要了解的同学可以去网上去查下资料。

接下来

img_f059a8bfdfdeb03e68bafd62743dbb79.png
next

img_1557fce6217006313ae6036d3fb1d49d.png
next

在此处勾选需要使用的功能模块,当然可以什么都不勾,等项目创建完毕后直接在pom.xml中添加也是可以的,需要注意的是SpringBoot在2.0之前JDK1.7都是支持的,但更新到2.0之后就需要1.8+了,所以在构建项目时,JDK的版本最好也更新到1.8+,maven也升级到3.2+

img_dbf41d5e2a46ed0dd2d2d3a16c6c3f1d.png
next

最后,填好工程名以及选择好工程地址就可以开始使用了SpringBoot了。

img_15dc130902353c6a63908829fc711b57.png
image.png

最后的结构如下图所示

img_b68738f51d5ce96aca7775dd6dcc9e01.png
image.png

这个Demo1Application是自动生成的也是我们待会需要运行的文件,这里需要注意的最好把该文件放在根目录下,不然可能会出现一些问题。

好了,接下来的话,开始运行这个文件

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

2018-10-08 14:22:07.086  INFO 5956 --- [           main] com.gabriel.Demo1Application             : Starting Demo1Application on stu with PID 5956 (C:\Users\Administrator.CDEDUASK_PC\IdeaProjects\demo1\target\classes started by Administrator in C:\Users\Administrator.CDEDUASK_PC\IdeaProjects\demo1)
2018-10-08 14:22:07.090  INFO 5956 --- [           main] com.gabriel.Demo1Application             : No active profile set, falling back to default profiles: default
2018-10-08 14:22:07.258  INFO 5956 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@2aa5fe93: startup date [Mon Oct 08 14:22:07 CST 2018]; root of context hierarchy
2018-10-08 14:22:09.050  INFO 5956 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2018-10-08 14:22:09.076  INFO 5956 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-10-08 14:22:09.076  INFO 5956 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.34
2018-10-08 14:22:09.090  INFO 5956 --- [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:\WorkSofe\java\jdk\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\WorkSofe\java\jdk\bin;%JAVA_HOME\jre\bin;C:\ProgramData\Oracle\Java\javapath;C:\WorkSofe\Oracle11\product\11.2.0\dbhome_1\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\WorkSofe\TortoiseSVN\bin;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5\;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5\Doctrine extensions for PHP\;C:\Program Files\Git\cmd;C:\Go\bin;C:\Program Files\VisualSVN Server\bin;C:\Users\Administrator.CDEDUASK_PC\AppData\Local\Programs\Python\Python37\Scripts\;C:\Users\Administrator.CDEDUASK_PC\AppData\Local\Programs\Python\Python37\;D:\sshAZ;%GOPATH%\bin;.]
2018-10-08 14:22:09.191  INFO 5956 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-10-08 14:22:09.191  INFO 5956 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1938 ms
2018-10-08 14:22:09.264  INFO 5956 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-10-08 14:22:09.270  INFO 5956 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-10-08 14:22:09.271  INFO 5956 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-10-08 14:22:09.271  INFO 5956 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-10-08 14:22:09.271  INFO 5956 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-10-08 14:22:09.419  INFO 5956 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-10-08 14:22:09.628  INFO 5956 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@2aa5fe93: startup date [Mon Oct 08 14:22:07 CST 2018]; root of context hierarchy
2018-10-08 14:22:09.727  INFO 5956 --- [           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)
2018-10-08 14:22:09.728  INFO 5956 --- [           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-10-08 14:22:09.756  INFO 5956 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-10-08 14:22:09.756  INFO 5956 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-10-08 14:22:09.957  INFO 5956 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-10-08 14:22:10.000  INFO 5956 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2018-10-08 14:22:10.004  INFO 5956 --- [           main] com.gabriel.Demo1Application             : Started Demo1Application in 3.753 seconds (JVM running for 4.316)

启动日志如上,看到端口了,访问一下吧


img_96e8e682b77102b2e0e1322f06bc4433.png
image.png

看到error page了? don't worry 我们来看看启动日志

img_cbd04d743f9b6197745c16c934912f5c.png
image.png

原来是没有配置映射,ok 我们打开Demo1Application来看看


img_4dceb811351a87b2f961f20498f828bf.png
image.png

给这个类加上映射来访问看看

img_f61547d127a037801533e2737b723173.png
image.png

看看这次的启动日志


img_1d0a130e1cf3aa4955225d174745df06.png
image.png

明显有个 / 被映射到了,这次应该没什么问题了,再次访问

img_c4f800070af053b5c34883f51fbca083.png
image.png

SpringBoot YES! 好了,我们的工程构建完毕了。

网友评论

登录后评论
0/500
评论
gabriel丶
+ 关注