文档章节

SpringBoot 2.0 系列003 -- 自定义Parent

路上有你0314
 路上有你0314
发布于 05/15 13:52
字数 1448
阅读 436
收藏 10

SpringBoot 2.0 系列003 --自定义Parent

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

使用自定义parent管理SpringBoot项目

第一步 配置父项目

  • 新建名为SpringBootLearn的maven空项目

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

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>SpringBootLearn</groupId>
  <artifactId>SpringBootLearn</artifactId>
  <version>1.0</version>
  <packaging>pom</packaging>
  <modules>
    <module>chapter01</module>
  </modules>

  <name>SpringBootLearn Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>| 交流群:244930845</url>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <!-- 此处是官方文档提供的必须要引入管理的文件 -->
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>2.0.1.RELEASE</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
        <!--此处是使用SpringBoot maven plugin必须添加的支持 不写的话后续版本可能会出现打包失败等问题-->
      <plugin>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-maven-plugin</artifactId>
          <version>2.0.1.RELEASE</version>
        <executions>
          <execution>
            <goals>
              <goal>repackage</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

第二步 配置子项目

  • 新建名为chapter03的maven空项目
  • 配置chapter03项目pom文件,如下
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>chapter03</groupId>
    <artifactId>chapter03</artifactId>
    <packaging>jar</packaging>
    <name>chapter03</name>
    <url>| 交流群:244930845</url>
    <!-- 引入parent依赖-->
    <parent>
        <groupId>SpringBootLearn</groupId>
        <artifactId>SpringBootLearn</artifactId>
        <version>1.0</version>
    </parent>

    <!--添加额外依赖 -->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

</project>
  • 配置启动类 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

  • 第二种方式

  • 运行,执行结果如下
"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

© 著作权归作者所有

共有 人打赏支持
路上有你0314
粉丝 49
博文 23
码字总数 45128
作品 0
郑州
程序员
SpringBoot 2.0 系列006 --启动实战之注解使用

SpringBoot 2.0 系列006 --启动实战之注解使用 一些误区说明 网上很多教程默认使用SpringBootApplcation注解,且只用这个即可扫描启动类包下所有的bean。 而官方默认教程使用的是@EnableAuto...

路上有你0314
05/18
0
0
SpringBoot 2.0 系列005 --启动实战之SpringApplication应用

SpringBoot 2.0 系列005 --启动实战之SpringApplication应用 2.X 官方示例 注意是只使用了@EnableAutoConfiguration,默认是只扫描这一个我们自定义的类到bean中。不含子包和本包。下一篇我们...

路上有你0314
05/17
0
0
SpringBoot 2.0 系列001 -- 入门介绍以及相关概念

SpringBoot 2.0 系列001 -- 入门介绍以及相关概念 什么是SpringBoot? 项目地址:http://projects.spring.io/spring-boot/ SpringBoot介绍 Spring Boot使开发独立的,产品级别的基于Spring的...

路上有你0314
05/10
0
0
学习 Spring Boot 知识看这一篇就够了

从2016年因为工作原因开始研究 Spring Boot ,先后写了很多关于 Spring Boot 的文章,发表在技术社区、我的博客和我的公号内。粗略的统计了一下总共的文章加起来大概有六十多篇了,其中一部分...

ityouknow
05/28
0
0
恒宇少年/spring-boot-chapter

简书整套文档以及源码解析 专题 专题名称 专题描述 001 Spring Boot 核心技术 讲解SpringBoot一些企业级层面的核心组件 002 Spring Cloud 核心技术 对Spring Cloud核心技术全面讲解 003 Quer...

恒宇少年
04/19
0
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

基于TP5的微信的公众号获取登录用户信息

之前讲过微信的公众号自动登录的菜单配置,这次记录一下在TP5项目中获取自动登录的用户信息并存到数据库的操作 基本的流程为:微信设置自动登录的菜单—>访问的URL指定的函数里获取用户信息—...

月夜中徘徊
今天
0
0
youTrack

package jetbrains.teamsys.license.runtime; 计算lis package jetbrains.ring.license.reader; 验证lis 安装后先不要生成lis,要把相关文件进行替换 ring-license-checker-1.0.41.jar char......

max佩恩
今天
0
0
12.17 Nginx负载均衡

Nginx负载均衡 下面的dig看到可以返回2个IP,就是解析出来的IP,这样我们可以做负载均衡。 dig www.qq.com 1.vim /usr/local/nginx/conf/vhost/fuzai.conf 2.添加如下配置 upstream qq //定义...

芬野de博客
今天
0
0
SSE(Server Send Event 服务端发送事件)

package com.example.demo.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframe......

Canaan_
今天
0
0
jvm调优

1.jvm运行模式 client模式:启动快,占用内存少,jit编译器生成代码的速度也更快. server模式:主要优势在于代码优化功能,这个功能对于服务器应用而言尤其重要. tiered server模式:结合了client与...

Funcy1122
今天
1
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

返回顶部
顶部