Skip to content

# 新建子模块

Maven多模块下新建子模块流程案例。

1、在hcp-modules下新建业务模块目录,例如:hcp-test

2、在hcp-test业务模块下新建pom.xml文件以及src\main\javasrc\main\resources目录。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <groupId>com.hcp</groupId>
        <artifactId>hcp-modules</artifactId>
        <version>x.x.x</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
	
    <artifactId>hcp-modules-test</artifactId>

    <description>
        hcp-modules-test系统模块
    </description>
	
    <dependencies>
    	
    	<!-- SpringCloud Alibaba Nacos -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>
        
        <!-- SpringCloud Alibaba Nacos Config -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>
        
    	<!-- SpringCloud Alibaba Sentinel -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
        </dependency>
        
    	<!-- SpringBoot Actuator -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
		
        <!-- Mysql Connector -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        
        <!-- hcp Common Security -->
        <dependency>
            <groupId>com.hcp</groupId>
            <artifactId>hcp-common-security</artifactId>
        </dependency>
        
        <!-- hcp Common Swagger -->
        <dependency>
            <groupId>com.hcp</groupId>
            <artifactId>hcp-common-swagger</artifactId>
        </dependency>
		
		<!-- hcp Common Log -->
        <dependency>
            <groupId>com.hcp</groupId>
            <artifactId>hcp-common-log</artifactId>
        </dependency>
        
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
   
</project>

3、在hcp-modules目录下pom.xml模块节点modules添加业务模块

<module>hcp-test</module>

1

4、src/main/resources添加bootstrap.yml文件

# Tomcat
server:
  port: 9301

# Spring
spring: 
  application:
    # 应用名称
    name: hcp-test
  profiles:
    # 环境配置
    active: dev
  cloud:
    nacos:
      discovery:
        # 服务注册地址
        server-addr: 127.0.0.1:8848
      config:
        # 配置中心地址
        server-addr: 127.0.0.1:8848
        # 配置文件格式
        file-extension: yml
        # 共享配置
        shared-configs:
          - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

5、com.hcp.test包下添加启动类

package com.hcp.test;

import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import com.hcp.common.security.annotation.EnableCustomConfig;
import com.hcp.common.security.annotation.EnablehcpFeignClients;
import com.hcp.common.swagger.annotation.EnableCustomSwagger2;

/**
 * 测试模块
 * 
 * @author hcp
 */
@EnableCustomConfig
@EnableCustomSwagger2
@EnablehcpFeignClients
@SpringCloudApplication
public class hcpTestApplication
{
    public static void main(String[] args)
    {
        SpringApplication.run(hcpTestApplication.class, args);
        System.out.println("(♥◠‿◠)ノ゙  测试模块启动成功   ლ(´ڡ`ლ)゙  \n");
    }
}

基于 MIT 许可发布