第一篇:SpringBoot 2.x 构建工程
简介
一直以来都想写点关于springboot的东西,每次遇到的问题又记不住,本次的记录也是拾人牙慧,写一点关于自己的理解。
SpringBoot关于它在官网上的介绍是这样的
一个基于Spring可以轻松创建的独立的,生产级别的应用,让你可以 “只管运行”
官方的解释不是重点,我们只需要去关注SpringBoot是如何做到只管运行
在这里使用官方的springio构建项目的方式以及eclipse的springboot插件的构建方式,我就说下关于idea的搭建方式,其余的方式这里就不再赘述了,想要了解的同学可以去网上去查下资料。
接下来
在此处勾选需要使用的功能模块,当然可以什么都不勾,等项目创建完毕后直接在pom.xml中添加也是可以的,需要注意的是SpringBoot在2.0之前JDK1.7都是支持的,但更新到2.0之后就需要1.8+了,所以在构建项目时,JDK的版本最好也更新到1.8+,maven也升级到3.2+
最后,填好工程名以及选择好工程地址就可以开始使用了SpringBoot了。
最后的结构如下图所示
这个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)
启动日志如上,看到端口了,访问一下吧
看到error page了? don't worry 我们来看看启动日志
原来是没有配置映射,ok 我们打开Demo1Application来看看
给这个类加上映射来访问看看
看看这次的启动日志
明显有个 / 被映射到了,这次应该没什么问题了,再次访问
SpringBoot YES! 好了,我们的工程构建完毕了。
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
python基础系列教程——Python的安装与测试:python解释器、PyDev编辑器、pycharm编译器
最近由于学习的需要,需要用到python,本文就简单的介绍一下Python的安装与测试。另外最近官网搞活动可以领代金券,有购买服务器需求的(不需要的可以忽略)可以领一下,领券地址:https://promotion.aliyun.com/ntms/yunparter/invite.html?userCode=qyowv5ea白手起家,从头开启python的开发环境搭建。一. 如何安装Python 在https://www.python.org/下载安装包。 下载下来一个exe文件,直接双击运行。 选择Install Now,立即安装。 配置环境变量:右键开始——控制面板——系统——高级系统配置——环境变量。 找到环境变量中的Path变量,将Python的安装路径复制进去,比如我的路径是:“C:UserscdlAppDataLocalProgramsPythonPython36”注意添加的过程中要使用英文逗号。二. Windows系统中测试是否成功安装Python 开始——运行——cmd打开命令行程序;输入“python”,如果出现版本信息则为安装成功。 三. 同时使用两个版本的Pyth...
- 下一篇
Python开发的十个Tips,你知道几个?
下面是十个Python中很有用的贴士和技巧。其中一些是初学这门语言常常会犯的错误。 注意:假设我们都用的是Python 3 1. 列表推导式 你有一个list:bag = [1, 2, 3, 4, 5] 现在你想让所有元素翻倍,让它看起来是这个样子:[2, 4, 6, 8, 10] 大多初学者,根据之前语言的经验会大概这样来做 bag = [ 1 , 2 , 3 , 4 , 5 ] for i in range(len(bag)): bag[i] = bag[i] * 2 但是有更好的方法: bag = [elem * 2 for elem in bag] 很简洁对不对?这叫做Python的列表推导式。 2. 遍历列表 还是上面的列表。如果可能尽量避免这样做: bag = [ 1 , 2 , 3 , 4 , 5 ] for i in range(len(bag)): print(bag[i]) 取而代之的应该是这样: bag = [ 1 , 2 , 3 , 4 , 5 ] for i in bag: print(i) 如果x是一个列表,你可以对它的元素进行迭代。多数情况下你不需要各元素...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- CentOS7,8上快速安装Gitea,搭建Git服务器
- CentOS6,7,8上安装Nginx,支持https2.0的开启
- CentOS关闭SELinux安全模块
- SpringBoot2初体验,简单认识spring boot2并且搭建基础工程
- CentOS8编译安装MySQL8.0.19
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作
- CentOS8安装MyCat,轻松搞定数据库的读写分离、垂直分库、水平分库
- CentOS8安装Docker,最新的服务器搭配容器使用
- CentOS7,CentOS8安装Elasticsearch6.8.6
- Red5直播服务器,属于Java语言的直播服务器