新建过程
大家好,这里是千寻简笔记,我是作者星辰,笔记内容整理并发布,内容有误请指出,笔记源码已开源,前往Gitee搜索《chihiro-notes》感谢您的观看。
作者各大平台直链: GitHub | Gitee | CSDN
Maven多模块下新建子模块流程案例。
1、在ruoyi-modules
下新建业务模块目录,例如:ruoyi-test
。
2、在ruoyi-test
业务模块下新建pom.xml
文件以及src\main\java
,src\main\resources
目录。
<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.ruoyigroupId>
<artifactId>ruoyi-modulesartifactId>
<version>x.x.xversion>
parent>
<modelVersion>4.0.0modelVersion>
<artifactId>ruoyi-modules-testartifactId>
<description>
ruoyi-modules-test系统模块
description>
<dependencies>
<dependency>
<groupId>com.alibaba.cloudgroupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discoveryartifactId>
dependency>
<dependency>
<groupId>com.alibaba.cloudgroupId>
<artifactId>spring-cloud-starter-alibaba-nacos-configartifactId>
dependency>
<dependency>
<groupId>com.alibaba.cloudgroupId>
<artifactId>spring-cloud-starter-alibaba-sentinelartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-actuatorartifactId>
dependency>
<dependency>
<groupId>mysqlgroupId>
<artifactId>mysql-connector-javaartifactId>
dependency>
<dependency>
<groupId>com.ruoyigroupId>
<artifactId>ruoyi-common-securityartifactId>
dependency>
<dependency>
<groupId>com.ruoyigroupId>
<artifactId>ruoyi-common-swaggerartifactId>
dependency>
<dependency>
<groupId>com.ruoyigroupId>
<artifactId>ruoyi-common-logartifactId>
dependency>
dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
<executions>
<execution>
<goals>
<goal>repackagegoal>
goals>
execution>
executions>
plugin>
plugins>
build>
project>
3、在ruoyi-modules
目录下pom.xml
模块节点modules添加业务模块
<module>ruoyi-testmodule>
4、src/main/resources
添加bootstrap.yml
文件
# Tomcat
server:
port: 9301
# Spring
spring:
application:
# 应用名称
name: ruoyi-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.ruoyi.test包下添加启动类
package com.chihiro.table;
import com.ruoyi.common.security.annotation.EnableCustomConfig;
import com.ruoyi.common.security.annotation.EnableRyFeignClients;
import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* 表格模块
*
* @author ruoyi
*/
@EnableCustomConfig
@EnableCustomSwagger2
@EnableRyFeignClients
@SpringBootApplication
public class ChihiroTableApplication
{
public static void main(String[] args)
{
SpringApplication.run(ChihiroTableApplication.class, args);
System.out.println("(♥◠‿◠)ノ゙ 表格模块启动成功 ლ(´ڡ`ლ)゙ \n" +
" .-------. ____ __ \n" +
" | _ _ \\ \\ \\ / / \n" +
" | ( ' ) | \\ _. / ' \n" +
" |(_ o _) / _( )_ .' \n" +
" | (_,_).' __ ___(_ o _)' \n" +
" | |\\ \\ | || |(_,_)' \n" +
" | | \\ `' /| `-' / \n" +
" | | \\ / \\ / \n" +
" ''-' `'-' `-..-' ");
}
}
不修改容易使404
1.登录上nacos,在 配置管理->配置列表 里找到 ruoyi-gateway-dev.yml ,点击 编辑
找到 routes 节点,参考写好的路由,增加自己子模块的路由
2.把 ruoyi-system-dev.yml 克隆一份,创建自己子模块的配置文件,修改里面的配置,特别注意 mybatis 节点的修改
自定义包名配置
@MapperScan 怎么扫描多个包
@MapperScan({"com.myapp.**.mapper","com.ruoyi.**.mapper"})
# spring配置
spring:
redis:
host: localhost
port: 6379
password:
datasource:
# 主库数据源
master:
driver-class-name: com.mysql.cj.jdbc.Driver
# url: jdbc:mysql://localhost:3306/ry-cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
url: jdbc:mysql://localhost:3306/ry-cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8
username: root
password: root
# 从库数据源
# slave:
# url: mongodb://localhost:27017/chihiro_table
# username:
# password:
# driver-class-name:
# swagger配置
swagger:
title: 代码生成接口文档
license: Powered By ruoyi
licenseUrl: https://ruoyi.vip