SpringBoot 2.0 系列003

Stella981
• 阅读 509

SpringBoot 2.0 系列003 --自定义Parent

默认我们使用SpringBoot的方式是通过SB的parent项目的方式,此种之前的教程中我们已经演示过了,这里不做赘述。

使用自定义parent管理SpringBoot项目

第一步 配置父项目

  • 新建名为SpringBootLearn的maven空项目

  • 配置我们的SpringBootLearn项目的pom文件,如下

4.0.0

SpringBootLearn SpringBootLearn 1.0 pom chapter01

SpringBootLearn Maven Webapp | 交流群:244930845 org.springframework.boot spring-boot-dependencies 2.0.1.RELEASE pom import

junit junit 4.11 test org.springframework.boot spring-boot-maven-plugin 2.0.1.RELEASE repackage

第二步 配置子项目

  • 新建名为chapter03的maven空项目
  • 配置chapter03项目pom文件,如下

4.0.0 chapter03 chapter03 jar chapter03 | 交流群:244930845 SpringBootLearn SpringBootLearn 1.0

<!--添加额外依赖 -->
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>
  • 配置启动类 com.ricky.SpringBootApplication 如下

@EnableAutoConfiguration //开启RestController注解 含有ResponseBody 即非页面形式 @RestController public class SpringBootApplication { private Logger logger = LoggerFactory.getLogger(getClass()); @GetMapping("/") public String home(HttpServletRequest request) { logger.info("HelloWorld 访问成功"); return "Hello World!"; }

/\*\*
 \* 开启SpringBoot服务
 \* @param args
 \*/
public static void main(String\[\] args) {
    SpringApplication.run(SpringBootApplication.class,args);
}

}

第三步 打包运行

  • 新建maven的run 配置 键入如下命令

package spring-boot:repackage spring-boot:run

SpringBoot 2.0 系列003

  • 第二种方式

SpringBoot 2.0 系列003

  • 运行,执行结果如下

"D:\Program Files\Java\jdk1.8.0_161\bin\java" -Dmaven.multiModuleProjectDirectory=D:\work\ideawork\SpringBootLearn\chapter03 "-Dmaven.home=D:\Program Files\JetBrains\IntelliJ IDEA 2017.3.5\plugins\maven\lib\maven3" "-Dclassworlds.conf=D:\Program Files\JetBrains\IntelliJ IDEA 2017.3.5\plugins\maven\lib\maven3\bin\m2.conf" "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2017.3.5\lib\idea_rt.jar=8585:D:\Program Files\JetBrains\IntelliJ IDEA 2017.3.5\bin" -Dfile.encoding=UTF-8 -classpath "D:\Program Files\JetBrains\IntelliJ IDEA 2017.3.5\plugins\maven\lib\maven3\boot\plexus-classworlds-2.5.2.jar" org.codehaus.classworlds.Launcher -Didea.version=2017.3.5 package spring-boot:repackage spring-boot:run [INFO] Scanning for projects... [INFO]
[INFO] ------------------------------------------------------------------------ [INFO] Building chapter03 1.0 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ chapter03 --- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ chapter03 --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ chapter03 --- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory D:\work\ideawork\SpringBootLearn\chapter03\src\test\resources [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ chapter03 --- [INFO] No sources to compile [INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ chapter03 --- [INFO] No tests to run. [INFO] [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ chapter03 --- [INFO] [INFO] --- spring-boot-maven-plugin:2.0.1.RELEASE:repackage (default) @ chapter03 --- [INFO] [INFO] --- spring-boot-maven-plugin:2.0.1.RELEASE:repackage (default-cli) @ chapter03 --- [INFO] [INFO] >>> spring-boot-maven-plugin:2.0.1.RELEASE:run (default-cli) > test-compile @ chapter03 >>> [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ chapter03 --- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ chapter03 --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ chapter03 --- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory D:\work\ideawork\SpringBootLearn\chapter03\src\test\resources [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ chapter03 --- [INFO] No sources to compile [INFO] [INFO] <<< spring-boot-maven-plugin:2.0.1.RELEASE:run (default-cli) < test-compile @ chapter03 <<< [INFO] [INFO] --- spring-boot-maven-plugin:2.0.1.RELEASE:run (default-cli) @ chapter03 ---

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

2018-05-15 13:33:14.377 INFO 25516 --- [ main] com.ricky.SpringBootApplication : Starting SpringBootApplication on jsb-bgt with PID 25516 (D:\work\ideawork\SpringBootLearn\chapter03\target\classes started by zdwljs in D:\work\ideawork\SpringBootLearn\chapter03) 2018-05-15 13:33:14.385 INFO 25516 --- [ main] com.ricky.SpringBootApplication : The following profiles are active: product 2018-05-15 13:33:14.512 INFO 25516 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@3697df31: startup date [Tue May 15 13:33:14 CST 2018]; root of context hierarchy 2018-05-15 13:33:16.837 INFO 25516 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 80 (http) 2018-05-15 13:33:16.881 INFO 25516 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2018-05-15 13:33:16.885 INFO 25516 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.29 2018-05-15 13:33:16.905 INFO 25516 --- [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: [D:\Program Files\Java\jdk1.8.0_161\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;d:\work\Git\cmd;C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Users\zdwljs\AppData\Local\Microsoft\WindowsApps;D:\Program Files\Java\jdk1.8.0_161\bin;;.] 2018-05-15 13:33:17.075 INFO 25516 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2018-05-15 13:33:17.076 INFO 25516 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2563 ms 2018-05-15 13:33:17.352 INFO 25516 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/] 2018-05-15 13:33:17.360 INFO 25516 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*] 2018-05-15 13:33:17.360 INFO 25516 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*] 2018-05-15 13:33:17.361 INFO 25516 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*] 2018-05-15 13:33:17.361 INFO 25516 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*] 2018-05-15 13:33:17.561 INFO 25516 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2018-05-15 13:33:17.911 INFO 25516 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@3697df31: startup date [Tue May 15 13:33:14 CST 2018]; root of context hierarchy 2018-05-15 13:33:18.059 INFO 25516 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/],methods=[GET]}" onto public java.lang.String com.ricky.SpringBootApplication.home(javax.servlet.http.HttpServletRequest) 2018-05-15 13:33:18.064 INFO 25516 --- [ 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-05-15 13:33:18.065 INFO 25516 --- [ 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-05-15 13:33:18.106 INFO 25516 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2018-05-15 13:33:18.106 INFO 25516 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2018-05-15 13:33:18.339 INFO 25516 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2018-05-15 13:33:18.404 INFO 25516 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 80 (http) with context path '' 2018-05-15 13:33:18.409 INFO 25516 --- [ main] com.ricky.SpringBootApplication : Started SpringBootApplication in 5.022 seconds (JVM running for 10.402)

演示项目地址,欢迎fork和star

码云:SpringBootLearn

最后

SpringBoot 2.0 系列001 -- 入门介绍以及相关概念

 SpringBoot 2.0 系列002 --运行流程分析

  • 作者ricky
  • 交流群:244930845
点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Wesley13 Wesley13
2年前
java将前端的json数组字符串转换为列表
记录下在前端通过ajax提交了一个json数组的字符串,在后端如何转换为列表。前端数据转化与请求varcontracts{id:'1',name:'yanggb合同1'},{id:'2',name:'yanggb合同2'},{id:'3',name:'yang
Jacquelyn38 Jacquelyn38
2年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Stella981 Stella981
2年前
SpringBoot 2.0 系列002
SpringBoot2.0系列002运行流程分析SpringBoot2.0系列001入门介绍以及相关概念(https://my.oschina.net/lt0314/blog/1810336)1\.SpringBoot运行的几种方式
Easter79 Easter79
2年前
Twitter的分布式自增ID算法snowflake (Java版)
概述分布式系统中,有一些需要使用全局唯一ID的场景,这种时候为了防止ID冲突可以使用36位的UUID,但是UUID有一些缺点,首先他相对比较长,另外UUID一般是无序的。有些时候我们希望能使用一种简单一些的ID,并且希望ID能够按照时间有序生成。而twitter的snowflake解决了这种需求,最初Twitter把存储系统从MySQL迁移
Wesley13 Wesley13
2年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Stella981 Stella981
2年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
2年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
3个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这