当前位置: 首页 > news >正文

ruoyi分布式在module下新建服务排坑指南

在module下新建服务排坑指南

一、在module下新建ruoyi-project模块时,默认是3.5.5 ,实际需要的项目是3.6.6,

而且建成之后因为若依模块命名比较乱,所已 pom要改为 ruoyi-modules-project,
在这里插入图片描述

二、ruoyi-modules-project最终pom


<?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.ruoyi</groupId><artifactId>ruoyi-modules</artifactId><version>3.6.6</version></parent><modelVersion>4.0.0</modelVersion><artifactId>ruoyi-modules-project</artifactId><description>ruoyi-project日报模块</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><!-- 引入系统服务的 Feign API --><dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-api-system</artifactId></dependency><!-- SpringBoot Actuator --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><!-- Mysql Connector --><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId></dependency><!-- RuoYi Common DataSource --><dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-common-datasource</artifactId></dependency><!-- RuoYi Common DataScope --><dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-common-datascope</artifactId></dependency><!-- RuoYi Common Log --><dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-common-log</artifactId></dependency><!-- RuoYi Common Swagger --><dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-common-swagger</artifactId></dependency></dependencies><build><finalName>${project.artifactId}</finalName><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>11</source><target>11</target></configuration></plugin></plugins></build></project>

而且根据nacos线上 gateway的配置,新增日报项目路由

在这里插入图片描述

根据已有的system的线上nacos配置,发现用的是整合配置

mybatis:
typeAliasesPackage: com.ruoyi.project
mapperLocations: classpath:mapper/**/*.xml

三、出现问题一

导致一直报这个错:

Field dailyReportMapper in com.ruoyi.project.service.impl.DailyReportServiceImpl required a bean of type 'com.ruoyi.project.mapper.DailyReportMapper' that could not be found. The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true) Action: Consider defining a bean of type 'com.ruoyi.project.mapper.DailyReportMapper' in your configuration.

原因:

有些版本里 MyBatis 依赖拆在 ruoyi-common-mybatis,有些直接合并到 ruoyi-common-datasource 里。

而版本(RuoYi-Cloud 3.6.6)里确实 没有单独的 ruoyi-common-mybatis 模块。说明 MyBatis 整合已经包含在 ruoyi-common-datasource 模块里

解决方式:

1.ruoyi-modules-project的pom增加

<!-- RuoYi Common DataSource(包含 MyBatis 整合) -->
<dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-common-datasource</artifactId>
</dependency>

2.然后在 Nacos 配置里加上 MyBatis 配置,和 system 模块保持一致:

mybatis:typeAliasesPackage: com.ruoyi.projectmapperLocations: classpath:mapper/**/*.xml
额外检查点
  1. DailyReportMapper

    • 必须放在 com.ruoyi.project.mapper 包下。

    • 建议写上 @Mapper 注解:

      @Mapper
      public interface DailyReportMapper extends BaseMapper<DailyReport> { }
      
  2. 启动类

    • 如果没自动扫到,可以手动指定:

      @SpringBootApplication
      @EnableDiscoveryClient
      @MapperScan("com.ruoyi.project.mapper")
      public class RuoYiProjectApplication {public static void main(String[] args) {SpringApplication.run(RuoYiProjectApplication.class, args);}
      }
      
  3. 目录结构

    ruoyi-modules/ruoyi-project/├── src/main/java/com/ruoyi/project/│     ├── domain/DailyReport.java│     ├── mapper/DailyReportMapper.java│     ├── service/impl/DailyReportServiceImpl.java│     └── controller/DailyReportController.java└── src/main/resources/mapper/DailyReportMapper.xml (如果有 xml)
    

四、出现问题二

以上都配置好了 发现包另一个错:

`ield remoteLogService in com.ruoyi.common.log.service.AsyncLogService required a bean of type 'com.ruoyi.system.api.RemoteLogService' that could not be found. The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true) Action: Consider defining a bean of type 'com.ruoyi.system.api.RemoteLogService' in your configurati`on.

AsyncLogService 想注入 RemoteLogService,但是 Spring 容器里没有这个 Bean

解决方案
1. 确认依赖

在你的 ruoyi-modules-project/pom.xml 里,加入:

<!-- 引入系统服务的 Feign API -->
<dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-api-system</artifactId>
</dependency>
2. 确认启动类

RuoYiProjectApplication 上,加上 Feign 扫描:

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients(basePackages = "com.ruoyi.system.api")  // ✅ 扫描 RemoteLogService
@MapperScan("com.ruoyi.project.mapper")RemoteLogService
public class RuoYiProjectApplication {public static void main(String[] args) {SpringApplication.run(RuoYiProjectApplication.class, args);}
}
3. 确认注册中心里有 ruoyi-system
  • 你要保证 ruoyi-system 模块已经启动,并且在 Nacos 里注册成功:

    http://localhost:8848/nacos → 服务列表 → ruoyi-system
    
  • 如果 ruoyi-project 启动时找不到 ruoyi-systemRemoteLogService 会注入失败。

自此错误解决服务注册成功

在这里插入图片描述

附件:

线上nacos的ruoyi-project-dev.yml配置

# spring配置
spring:
redis:
host: 126.231.35.23
port: 6379
password: redis
datasource:
druid:
stat-view-servlet:
enabled: true
loginUsername: sertweg
loginPassword: sertweg
dynamic:
druid:
initial-size: 5
min-idle: 5
maxActive: 20
maxWait: 60000
connectTimeout: 30000
socketTimeout: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
filters: stat,slf4j
connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
datasource:
# 主库数据源
master:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://126.231.35.23:3306/sertweg?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: sertweg
password: sertweg
# 从库数据源
# slave:
# username:
# password:
# url:
# driver-class-name:# mybatis配置
mybatis:
# 搜索指定包别名
typeAliasesPackage: com.ruoyi.project
# 配置mapper的扫描,找到所有的mapper.xml映射文件
mapperLocations: classpath:mapper/**/*.xml# springdoc配置
springdoc:
gatewayUrl: http://126.231.35.23:8848/${spring.application.name}
api-docs:
# 是否开启接口文档
enabled: true
info:
# 标题
title: '日报模块接口文档'
# 描述
description: '日报模块接口描述'

peoject本地配置bootstrap.yml

# # Tomcat
server:
port: 9221# Spring
spring:
application:
# 应用名称
name: ruoyi-project
profiles:
# 环境配置
active: dev
cloud:
nacos:
username: nacos
password: bXksdfasdfasdfasdfsDkw
discovery:
# 服务注册地址
server-addr: 165.56.326.22:8848config:# 配置中心地址server-addr: 165.56.326.22:8848# 配置文件格式file-extension: yml# 共享配置shared-configs:- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}#读取配置中心文件配置
config:
import:
- optional:nacos:${spring.application.name}.${spring.cloud.nacos.config.file-extension}
sentinel:
# 取消控制台懒加载
eager: true
transport:
# 控制台地址
dashboard: 165.56.326.22:8718
# nacos配置持久化
datasource:
ds1:
nacos:
server-addr: 165.56.326.22:8848
dataId: sentinel-ruoyi-gateway
groupId: DEFAULT_GROUP
data-type: json
rule-type: gw-flow
logging:
level:
com.alibaba.cloud.nacos.config: DEBUG

文章转载自:

http://Qw7LFgIi.gyfzp.cn
http://pP1biQLi.gyfzp.cn
http://GVnShGm3.gyfzp.cn
http://2pVUeJB9.gyfzp.cn
http://7dZ96MDi.gyfzp.cn
http://igZn90P6.gyfzp.cn
http://QW8iCvTp.gyfzp.cn
http://2qOMbmqG.gyfzp.cn
http://yew2R6ex.gyfzp.cn
http://2WQMk6Gn.gyfzp.cn
http://G2smM3D5.gyfzp.cn
http://mTZIncN1.gyfzp.cn
http://jVGRANI9.gyfzp.cn
http://4z7wlBDn.gyfzp.cn
http://uwHPXpfZ.gyfzp.cn
http://EBfw54li.gyfzp.cn
http://CrXKQyyP.gyfzp.cn
http://7O9pIgW0.gyfzp.cn
http://HKPvqssQ.gyfzp.cn
http://RCMuFngf.gyfzp.cn
http://HeDBfZ3O.gyfzp.cn
http://NcnAJqBd.gyfzp.cn
http://DdPyWU91.gyfzp.cn
http://9NdYPLzb.gyfzp.cn
http://TIzjttZ2.gyfzp.cn
http://RGJgiBE1.gyfzp.cn
http://euDDy2lQ.gyfzp.cn
http://RZd1k75S.gyfzp.cn
http://1cqqlPKZ.gyfzp.cn
http://xgehuCzg.gyfzp.cn
http://www.dtcms.com/a/384199.html

相关文章:

  • prometheus-2.42.0.linux-amd64.tar.gz 安装配置展示
  • 1台SolidWorks服务器能带8-10人并发使用
  • 中国制造难点在哪里?
  • 网编_HW_9.15
  • 前端基础知识---10 Node.js(一)
  • C语言:求三个整数中的最大值
  • AI 赋能大前端电商应用:智能尺码推荐与搭配建议,重构购物体验
  • 跨境通信合规新解:Z世代多模态交互技术突破
  • SpringBoot返回前端时间格式化处理
  • 高系分四:网络分布式
  • Python 3.9.21 升级到 Python >=3.10
  • 在运维工作中,FTP主动和被动的区别有哪些?
  • CE-Agent 多智能体系统流程图文档
  • 数据结构——逻辑结构物理结构
  • RuoYi-Vue3-FastAPI框架的功能实现(下)
  • PySpark简化数据处理的高效函数有哪些?
  • 哈尔滨云前沿服务器租用托管
  • React项目 新闻发布系统 项目初始化与路由搭建
  • 数字经济专业核心课程解析与职业发展指南
  • Spring Boot 全栈优化:服务器、数据、缓存、日志的场景应用!
  • 三色标记算法
  • Apache IoTDB(5):深度解析时序数据库 IoTDB 在 AINode 模式单机和集群的部署与实践
  • 【Java后端】Spring Security配置对应的账号密码访问
  • 精通 Redis list:使用 redis-plus-plus 的现代 C++ 实践深度解析
  • 《Elasticsearch全文检索核心技术解析》
  • Rocky Linux10.0修改ip地址
  • DevOps实战(7) - 使用Arbess+GitPuk+sourcefare实现Node.js项目自动化部署
  • 学习日报|梳理三类典型缓存问题:缓存穿透、缓存击穿、缓存雪崩
  • 【JavaEE】线程安全-内存可见性、指令全排序
  • MCP传输机制完全指南:Stdio、SSE、Streamable HTTP详解-实践案例-整体对比