您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这篇文章主要介绍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子父项目启动成功。
以上是“Springboot如何创建子父工程”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。