Springboot创建子父工程过程图解

 更新时间:2020年02月19日 10:04:14   作者:泡椒炒甜瓜  
这篇文章主要介绍了Springboot创建子父工程过程图解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

这篇文章主要介绍了Springboot创建子父工程过程图解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

1.创建子父工程

2.添加pom配置文件

2.1 父工程pom.xml

<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>com.demo</groupId>
 <artifactId>springboot</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <packaging>pom</packaging>
 <modules>
   <module>springboot-server</module>
   <module>springboot-common</module>
   <module>springboot-domain</module>
   <module>springboot-sdk</module>
 </modules>
 
 
 <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <build.jdk.version>1.8</build.jdk.version>
    <spring.boot.version>1.5.9.RELEASE</spring.boot.version>
    <spring.version>4.3.13.RELEASE</spring.version>
    <slf4j.version>1.7.25</slf4j.version>
    <fastjson.version>1.2.8</fastjson.version>
    <commons.lang.version>3.1</commons.lang.version>
    <commons.io.version>2.5</commons.io.version>
    <commons.beanutils.version>1.9.3</commons.beanutils.version>
    <commons.codec.version>1.11</commons.codec.version>
    <guava.version>19.0</guava.version>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <version>${spring.boot.version}</version>
      </dependency>

      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
        <version>${spring.boot.version}</version>
      </dependency>

      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>${spring.boot.version}</version>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
      </dependency>

      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
      </dependency>

      <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
        <version>${fastjson.version}</version>
      </dependency>


      <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>${commons.lang.version}</version>
      </dependency>

      <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>${commons.io.version}</version>
      </dependency>
      <dependency>
        <groupId>commons-beanutils</groupId>
        <artifactId>commons-beanutils</artifactId>
        <version>${commons.beanutils.version}</version>
      </dependency>
      <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>${commons.codec.version}</version>
      </dependency>

      <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>${guava.version}</version>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <version>${spring.boot.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>${slf4j.version}</version>
    </dependency>
  </dependencies>

  <distributionManagement>
    <repository>
      <id>nexus-releases</id>
      <name>Nexus Release Repository</name>
      <url>http://ip:9090/repository/releases/</url>
    </repository>
    <snapshotRepository>
      <id>nexus-snapshots</id>
      <name>Nexus Snapshot Repository</name>
      <url>http://ip:9090/repository/snapshots/</url>
    </snapshotRepository>
  </distributionManagement>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>${build.jdk.version}</source>
          <target>${build.jdk.version}</target>
        </configuration>
      </plugin>

      <!-- 使用方式命令: versions:set -DoldVersion=* -DnewVersion=1.0.1-SNAPSHOT -DprocessAllModules=true 
        -DallowSnapshots=true -->
      <plugin>
        <groupId>org.sonarsource.scanner.maven</groupId>
        <artifactId>sonar-maven-plugin</artifactId>
        <version>3.2</version>
      </plugin>
    </plugins>
  </build>
  
</project>

2.2 子工程springboot-server pom.xml:

<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>
 <parent>
  <groupId>com.demo</groupId>
  <artifactId>springboot</artifactId>
  <version>0.0.1-SNAPSHOT</version>
 </parent>
 <artifactId>springboot-server</artifactId>
 
 <name>springboot-server</name>
 <properties>
    <application.main.class>com.demo.Application</application.main.class>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>fastjson</artifactId>
    </dependency>

    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId>
    </dependency>

    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
    </dependency>
    <dependency>
      <groupId>commons-beanutils</groupId>
      <artifactId>commons-beanutils</artifactId>
    </dependency>
    <dependency>
      <groupId>commons-codec</groupId>
      <artifactId>commons-codec</artifactId>
    </dependency>
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
    </dependency>

    <dependency>
      <groupId>net.sf.ehcache</groupId>
      <artifactId>ehcache</artifactId>
      <version>2.10.5</version>
    </dependency>
  </dependencies>

  <build>
    <sourceDirectory>src/main/java</sourceDirectory>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
        <includes>
          <include>*.properties</include>
          <include>*.yml</include>
          <include>*.xml</include>
        </includes>
      </resource>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>false</filtering>
        <excludes>
          <exclude>scripts/*</exclude>
          <exclude>*.properties</exclude>
          <exclude>*.yml</exclude>
          <exclude>*.xml</exclude>
        </excludes>
      </resource>

      <!-- 收集运行脚本 -->
      <resource>
        <directory>src/main/resources/scripts</directory>
        <targetPath>${project.build.directory}/bin</targetPath>
        <filtering>true</filtering>
        <includes>
          <include>*.sh</include>
          <include>*.bat</include>
        </includes>
      </resource>
      <!-- 收集配置文件 -->
      <resource>
        <directory>src/main/resources</directory>
        <targetPath>${project.build.directory}/conf</targetPath>
        <filtering>true</filtering>
        <includes>
          <include>*.properties</include>
          <include>*.yml</include>
          <include>*.xml</include>
        </includes>
      </resource>

      <!-- 收集手动导入的jar包 -->
      <resource>
        <directory>lib</directory>
        <targetPath>${project.build.directory}/lib</targetPath>
      </resource>
    </resources>
    <plugins>
      <!-- 1.用于编译的plugin -->
      <!-- <plugin> -->
      <!-- <groupId>org.apache.maven.plugins</groupId> -->
      <!-- <artifactId>maven-compiler-plugin</artifactId> -->
      <!-- <version>3.1</version> -->
      <!-- <configuration> -->
      <!-- <fork>true</fork> -->
      <!-- <source>1.8</source> -->
      <!-- <target>1.8</target> -->
      <!-- <encoding>UTF-8</encoding> -->
      <!-- </configuration> -->
      <!-- </plugin> -->

      <!-- 2.用于生成jar包的plugin -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <outputDirectory>${project.build.directory}/lib</outputDirectory>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
              <classpathPrefix>lib/</classpathPrefix>
            </manifest>
          </archive>
          <excludes>
            <exclude>*.xml</exclude>
            <exclude>*.yml</exclude>
            <exclude>*.properties</exclude>
          </excludes>
        </configuration>
      </plugin>

      <!-- 3.用于拷贝maven依赖(lib)的plugin -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.directory}/lib</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- 4.用于拷贝resource文件夹 的plugin -->

      <!-- 5.配置生成源代码jar的plugin[这里的源代码是指java文件,不是class文件] -->
      <plugin>
        <artifactId>maven-source-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <attach>true</attach>
          <!-- 配置源代码jar文件的存放路径 -->
          <outputDirectory>${project.build.directory}</outputDirectory>
        </configuration>
        <executions>
          <execution>
            <phase>compile</phase>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <!-- 打包zip -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
          <execution>
            <id>dfrp-portal</id>
            <configuration>
              <archive>
                <manifest>
                  <mainClass>${application.main.class}</mainClass>
                </manifest>
              </archive>
              <descriptors>
                <descriptor>src/main/resources/scripts/assembly.xml</descriptor>
              </descriptors>
              <!-- 将依赖jar包都包含在目标jar中 -->
              <!-- <descriptorRefs> -->
              <!-- <descriptorRef>jar-with-dependencies</descriptorRef> -->
              <!-- </descriptorRefs> -->
              <finalName>${project.name}-${version}</finalName>
            </configuration>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
 
 
</project>

3.App启动类

/**
 * Copyright (c) 2020, All Rights Reserved.
 *
*/

package com.demo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
  private static final Logger LOG = LoggerFactory.getLogger(Application.class);

  public static void main(String[] args) {
    SpringApplication app = new SpringApplication(Application.class);
    app.setBannerMode(Banner.Mode.OFF);
    app.setWebEnvironment(true);
    app.run(args);
    LOG.info("**************** Startup Success ****************");
  }
}

4.application.yml配置文件

version: ${project.version}

server:
 port: 7070
 session-timeout: 0
 context-path: /

5.测试controller类

package com.demo.server.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
  
  @RequestMapping("/helloworld")
  public String hello(String name) {
    return "name"+name;
  }

}

springboot子父项目启动成功。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • Mybatis-plus sql注入及防止sql注入详解

    Mybatis-plus sql注入及防止sql注入详解

    mybatis-plus提供了许多默认单表 CRUD 语句,对于其他SQL情况爱莫能助,下面这篇文章主要给大家介绍了关于Mybatis-plus sql注入及防止sql注入的相关资料,文中通过实例代码介绍的非常详细,需要的朋友可以参考下
    2022-10-10
  • Java轻量级权限认证框架Sa-Token的使用

    Java轻量级权限认证框架Sa-Token的使用

    Sa-Token是一个轻量级Java权限认证框架,本文就详细的来介绍一下Java轻量级权限认证框架Sa-Token的使用,主要解决:登录认证、权限认证、Session会话、单点登录、OAuth2.0、微服务网关鉴权等,感兴趣的可以了解一下
    2022-03-03
  • Spring通过配置文件和注解实现属性赋值

    Spring通过配置文件和注解实现属性赋值

    这篇文章主要介绍了Spring通过配置文件和注解实现属性赋值,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-04-04
  • Java 如何使用JDBC连接数据库

    Java 如何使用JDBC连接数据库

    这篇文章主要介绍了Java 如何使用JDBC连接数据库,帮助大家更好的理解和学习使用Java,感兴趣的朋友可以了解下
    2021-02-02
  • springboot动态调用实现类方式

    springboot动态调用实现类方式

    这篇文章主要介绍了springboot动态调用实现类方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2021-11-11
  • spring-boot使用AOP统一处理日志

    spring-boot使用AOP统一处理日志

    这篇文章主要为大家详细介绍了spring-boot使用AOP统一处理日志,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2016-12-12
  • SpringMVC中Controller类数据响应的方法

    SpringMVC中Controller类数据响应的方法

    这篇文章主要介绍了SpringMVC中的数据响应的问题,主要来了解 Controller 类如何进行数据响应的,本文给大家介绍的非常详细,需要的朋友可以参考下
    2021-07-07
  • Java并发统计变量值偏差原因及解决方案

    Java并发统计变量值偏差原因及解决方案

    这篇文章主要介绍了Java并发统计变量值偏差原因及解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-06-06
  • 快速入门Java中的Lambda表达式

    快速入门Java中的Lambda表达式

    Lambda作为函数式编程中的基础部分,在其他编程语言中早就广为使用,但在Java领域中发展较慢,直到java8,才开始支持Lambda。网上关于Lambda的教程很多,今天小编给大家分享一篇快速入手Lambda的教程。
    2016-08-08
  • Java Metrics系统性能监控工具的使用详解

    Java Metrics系统性能监控工具的使用详解

    Metrics是一个Java库,可以对系统进行监控,统计一些系统的性能指标。本文就来和大家详细聊聊这个工具的具体使用,希望对大家有所帮助
    2022-11-11

最新评论