请选择 进入手机版 | 继续访问电脑版

[项目(Java)] [若依]微服务springcloud版新建增添加一个业务子模块微服务

技术实战 技术实战 3929 人阅读 | 0 人回复

若依框架是一个比较出名的后台管理系统,有多个不同版本。 本文介绍微服务版本如何新增一个微服务模块,类似System模块,对外提供服务。 阅读使用本文的前提是已经成功搭建起来了ruoyi的springcloud版本的环境。

新建模块

在modules模块下新建module image.png 根据实际需要填写即可 image.png

创建完成之后,删除无用的内容,比如resource下的template,按需删除即可

设置pom

直接复制ruoyi-modules-system的系统模块的pom.xml,然后对其内容进行修改,仅仅需要修改两个点,一个是artifactId一个是description image.png 本文作者:程序员潇然 疯狂的字节X https://crazybytex.com/

设置resource内容

复制ruoyi-system的resources文件夹下的banner.txt,bootstrap.yml,logback.xml文件到ruoyi-xxx模块(刚才新建的模块)

修改banner

banner动画,自行设置即可,有很多生成网站

修改bootstrap.yml

端口号修改为你需要的,比如9205 修改应用名称,如ruoyi-xxx

# Tomcat
server:
  port: 9205

# Spring
spring: 
  application:
    # 应用名称
    name: ruoyi-xxx

修改logback.xml中日志存放路径

<!-- 日志存放路径 -->
<property name="log.path" value="logs/ruoyi-xxx" />

配置nacos

创建配置

登录nacos,根据system配置文件,克隆一个 image.png 注意dataID为 ruoyi-xxx-dev dev是环境 image.png

修改mybatis部分配置

mybatis:
    # 搜索指定包别名
    typeAliasesPackage: com.ruoyi.xxx
    # 配置mapper的扫描,找到所有的mapper.xml映射文件
    mapperLocations: classpath:mapper/**/*.xml

配置网关

修改ruoyi-gateway-dev.yml网管的配置文件,仿照上面system的配置复制出来一份,并修改为新模块所对应的。

# xxx模块
        - id: ruoyi-xxx
          uri: lb://ruoyi-xxx
          predicates:
            - Path=/xxx/**
          filters:
            - StripPrefix=1

配置sentinel

修改配置文件 sentinel-ruoyi-gateway

{
        "resource": "ruoyi-xxx",
        "count": 1000,
        "grade": 1,
        "limitApp": "default",
        "strategy": 0,
        "controlBehavior": 0
    },

调整启动类

参照RuoYiSystemApplication,具体地说就是直接复制几个注解即可,参考代码如下

@EnableCustomConfig
@EnableCustomSwagger2
@EnableRyFeignClients
@SpringBootApplication
public class RuoYiSystemApplication
{
    public static void main(String[] args)
    {
        SpringApplication.run(RuoYiSystemApplication.class, args);
        System.out.println("(♥◠‿◠)ノ゙  系统模块启动成功   ლ(´ڡ`ლ)゙  \n" +
                " .-------.       ____     __        \n" +
                " |  _ _   \\      \\   \\   /  /    \n" +
                " | ( ' )  |       \\  _. /  '       \n" +
                " |(_ o _) /        _( )_ .'         \n" +
                " | (_,_).' __  ___(_ o _)'          \n" +
                " |  |\\ \\  |  ||   |(_,_)'         \n" +
                " |  | \\ `'   /|   `-'  /           \n" +
                " |  |  \\    /  \\      /           \n" +
                " ''-'   `'-'    `-..-'              ");
    }
}

配置完成,启动

Spring Boot Version: 2.6.7
Spring Application Name: ruoyi-xxx
                            _
                           (_)
 _ __  _   _   ___   _   _  _  ______  ___  _   _  ___
| '__|| | | | / _ \ | | | || ||______|/ __|| | | |/ __
| |   | |_| || (_) || |_| || |        \__ \| |_| |\__
|_|    \__,_| \___/  \__, ||_|        |___/ \__, ||___
                      __/ |                  __/ |
                     |___/                  |___/
11:41:40.279 [main] INFO  c.a.n.c.r.client - [lambda$createClient$0,80] - [RpcClientFactory] create a new rpc client of b51ae82a-d313-44e9-b3c5-5c5d744fd091_config-0
11:41:40.311 [main] INFO  o.r.Reflections - [scan,232] - Reflections took 20 ms to scan 1 urls, producing 3 keys and 6 values 
11:41:40.333 [main] INFO  o.r.Reflections - [scan,232] - Reflections took 10 ms to scan 1 urls, producing 4 keys and 9 values 
11:41:40.346 [main] INFO  o.r.Reflections - [scan,232] - Reflections took 11 ms to scan 1 urls, producing 3 keys and 10 values 
11:41:40.492 [main] INFO  o.r.Reflections - [scan,232] - Reflections took 144 ms to scan 246 urls, producing 0 keys and 0 values 
11:41:40.503 [main] INFO  o.r.Reflections - [scan,232] - Reflections took 10 ms to scan 1 urls, producing 1 keys and 5 values 
11:41:40.514 [main] INFO  o.r.Reflections - [scan,232] - Reflections took 9 ms to scan 1 urls, producing 1 keys and 7 values 
11:41:40.524 [main] INFO  o.r.Reflections - [scan,232] - Reflections took 7 ms to scan 1 urls, producing 2 keys and 8 values 
11:41:40.666 [main] INFO  o.r.Reflections - [scan,232] - Reflections took 140 ms to scan 246 urls, producing 0 keys and 0 values 
11:41:40.667 [main] INFO  c.a.n.c.r.client - [printIfInfoEnabled,60] - [b51ae82a-d313-44e9-b3c5-5c5d744fd091_config-0] RpcClient init label, labels = {module=config, Vipserver-Tag=null, source=sdk, Amory-Tag=null, Location-Tag=null, taskId=0, AppName=unknown}
11:41:40.668 [main] INFO  c.a.n.c.r.client - [printIfInfoEnabled,60] - [b51ae82a-d313-44e9-b3c5-5c5d744fd091_config-0] Register server push request handler:com.alibaba.nacos.client.config.impl.ClientWorker$ConfigRpcTransportClient$$Lambda$332/1716411886
11:41:40.668 [main] INFO  c.a.n.c.r.client - [printIfInfoEnabled,60] - [b51ae82a-d313-44e9-b3c5-5c5d744fd091_config-0] Register server push request handler:com.alibaba.nacos.client.config.impl.ClientWorker$ConfigRpcTransportClient$$Lambda$333/1126112943
11:41:40.668 [main] INFO  c.a.n.c.r.client - [printIfInfoEnabled,60] - [b51ae82a-d313-44e9-b3c5-5c5d744fd091_config-0] Registry connection listener to current client:com.alibaba.nacos.client.config.impl.ClientWorker$ConfigRpcTransportClient$1
11:41:40.669 [main] INFO  c.a.n.c.r.client - [printIfInfoEnabled,60] - [b51ae82a-d313-44e9-b3c5-5c5d744fd091_config-0] RpcClient init, ServerListFactory = com.alibaba.nacos.client.config.impl.ClientWorker$ConfigRpcTransportClient$2
11:41:40.675 [main] INFO  c.a.n.c.r.client - [printIfInfoEnabled,60] - [b51ae82a-d313-44e9-b3c5-5c5d744fd091_config-0] Try to connect to server on start up, server: {serverIp = '127.0.0.1', server main port = 8848}
11:41:41.791 [main] INFO  c.a.n.c.r.client - [printIfInfoEnabled,60] - [b51ae82a-d313-44e9-b3c5-5c5d744fd091_config-0] Success to connect to server [127.0.0.1:8848] on start up, connectionId = 1657165301628_127.0.0.1_58242
11:41:41.792 [com.alibaba.nacos.client.remote.worker] INFO  c.a.n.c.r.client - [printIfInfoEnabled,60] - [b51ae82a-d313-44e9-b3c5-5c5d744fd091_config-0] Notify connected event to listeners.
11:41:41.792 [main] INFO  c.a.n.c.r.client - [printIfInfoEnabled,60] - [b51ae82a-d313-44e9-b3c5-5c5d744fd091_config-0] Register server push request handler:com.alibaba.nacos.common.remote.client.RpcClient$ConnectResetRequestHandler
11:41:41.792 [main] INFO  c.a.n.c.r.client - [printIfInfoEnabled,60] - [b51ae82a-d313-44e9-b3c5-5c5d744fd091_config-0] Register server push request handler:com.alibaba.nacos.common.remote.client.RpcClient$$Lambda$342/554510956
11:41:41.831 [main] WARN  c.a.c.n.c.NacosPropertySourceBuilder - [loadNacosData,87] - Ignore the empty nacos configuration and get it based on dataId[ruoyi-xxx] & group[DEFAULT_GROUP]
11:41:41.834 [main] WARN  c.a.c.n.c.NacosPropertySourceBuilder - [loadNacosData,87] - Ignore the empty nacos configuration and get it based on dataId[ruoyi-xxx.yml] & group[DEFAULT_GROUP]
11:41:41.847 [main] INFO  c.u.z.d.ZeusDeviceApplication - [logStartupProfileInfo,646] - The following 1 profile is active: "dev"
11:41:42.948 [main] WARN  o.m.s.m.ClassPathMapperScanner - [warn,44] - No MyBatis mapper was found in '[com.ubeesky.ruoyi.**.mapper]' package. Please check your configuration.
11:41:43.590 [main] INFO  o.a.c.h.Http11NioProtocol - [log,173] - Initializing ProtocolHandler ["http-nio-9205"]
11:41:43.591 [main] INFO  o.a.c.c.StandardService - [log,173] - Starting service [Tomcat]
11:41:43.591 [main] INFO  o.a.c.c.StandardEngine - [log,173] - Starting Servlet engine: [Apache Tomcat/9.0.62]
11:41:43.728 [main] INFO  o.a.c.c.C.[.[.[/] - [log,173] - Initializing Spring embedded WebApplicationContext
11:41:44.260 [main] INFO  c.a.c.s.SentinelWebMvcConfigurer - [addInterceptors,52] - [Sentinel Starter] register SentinelWebInterceptor with urlPatterns: [/**].
11:41:45.304 [main] INFO  c.a.n.c.r.client - [lambda$createClient$0,80] - [RpcClientFactory] create a new rpc client of 6a322d33-20ea-4493-9563-8de7319312da
11:41:45.305 [main] INFO  c.a.n.c.r.client - [printIfInfoEnabled,60] - [6a322d33-20ea-4493-9563-8de7319312da] RpcClient init label, labels = {module=naming, source=sdk}
11:41:45.306 [main] INFO  c.a.n.c.r.client - [printIfInfoEnabled,60] - [6a322d33-20ea-4493-9563-8de7319312da] RpcClient init, ServerListFactory = com.alibaba.nacos.client.naming.core.ServerListManager
11:41:45.306 [main] INFO  c.a.n.c.r.client - [printIfInfoEnabled,60] - [6a322d33-20ea-4493-9563-8de7319312da] Registry connection listener to current client:com.alibaba.nacos.client.naming.remote.gprc.redo.NamingGrpcRedoService
11:41:45.307 [main] INFO  c.a.n.c.r.client - [printIfInfoEnabled,60] - [6a322d33-20ea-4493-9563-8de7319312da] Register server push request handler:com.alibaba.nacos.client.naming.remote.gprc.NamingPushRequestHandler
11:41:45.307 [main] INFO  c.a.n.c.r.client - [printIfInfoEnabled,60] - [6a322d33-20ea-4493-9563-8de7319312da] Try to connect to server on start up, server: {serverIp = '127.0.0.1', server main port = 8848}
11:41:45.420 [main] INFO  c.a.n.c.r.client - [printIfInfoEnabled,60] - [6a322d33-20ea-4493-9563-8de7319312da] Success to connect to server [127.0.0.1:8848] on start up, connectionId = 1657165305310_127.0.0.1_58246
11:41:45.420 [com.alibaba.nacos.client.remote.worker] INFO  c.a.n.c.r.client - [printIfInfoEnabled,60] - [6a322d33-20ea-4493-9563-8de7319312da] Notify connected event to listeners.
11:41:45.420 [main] INFO  c.a.n.c.r.client - [printIfInfoEnabled,60] - [6a322d33-20ea-4493-9563-8de7319312da] Register server push request handler:com.alibaba.nacos.common.remote.client.RpcClient$ConnectResetRequestHandler
11:41:45.420 [main] INFO  c.a.n.c.r.client - [printIfInfoEnabled,60] - [6a322d33-20ea-4493-9563-8de7319312da] Register server push request handler:com.alibaba.nacos.common.remote.client.RpcClient$$Lambda$342/554510956
11:41:45.964 [main] INFO  c.a.d.p.DruidDataSource - [init,998] - {dataSource-1,master} inited
11:41:45.965 [main] INFO  c.b.d.d.DynamicRoutingDataSource - [addDataSource,148] - dynamic-datasource - add a datasource named [master] success
11:41:45.965 [main] INFO  c.b.d.d.DynamicRoutingDataSource - [afterPropertiesSet,228] - dynamic-datasource initial loaded [1] datasource,primary datasource named [master]
11:41:47.481 [main] INFO  o.a.c.h.Http11NioProtocol - [log,173] - Starting ProtocolHandler ["http-nio-9205"]
11:41:47.500 [main] INFO  c.a.c.n.r.NacosServiceRegistry - [register,75] - nacos registry, DEFAULT_GROUP ruoyi-xxx 192.168.1.115:9205 register finished
11:41:47.800 [main] INFO  c.u.z.d.ZeusDeviceApplication - [logStarted,61] - Started ZeusDeviceApplication in 8.858 seconds (JVM running for 9.67)
11:41:47.806 [main] INFO  c.a.c.n.r.NacosContextRefresher - [registerNacosListenersForApplications,105] - listening config: dataId=ruoyi-xxx, group=DEFAULT_GROUP
11:41:47.807 [main] INFO  c.a.c.n.r.NacosContextRefresher - [registerNacosListenersForApplications,105] - listening config: dataId=ruoyi-xxx-dev.yml, group=DEFAULT_GROUP
11:41:47.808 [main] INFO  c.a.c.n.r.NacosContextRefresher - [registerNacosListenersForApplications,105] - listening config: dataId=ruoyi-xxx.yml, group=DEFAULT_GROUP
11:41:47.991 [nacos-grpc-client-executor-6] INFO  c.a.n.c.r.client - [printIfInfoEnabled,60] - [6a322d33-20ea-4493-9563-8de7319312da] Receive server push request, request = NotifySubscriberRequest, requestId = 9
11:41:47.994 [nacos-grpc-client-executor-6] INFO  c.a.n.c.r.client - [printIfInfoEnabled,60] - [6a322d33-20ea-4493-9563-8de7319312da] Ack server push request, request = NotifySubscriberRequest, requestId = 9
11:41:48.485 [RMI TCP Connection(1)-192.168.56.1] INFO  o.a.c.c.C.[.[.[/] - [log,173] - Initializing Spring DispatcherServlet 'dispatcherServlet'
INFO: Sentinel log output type is: file
INFO: Sentinel log charset is: utf-8
INFO: Sentinel log base directory is: C:\Users\PC\logs\csp\
INFO: Sentinel log name use pid is: false

查看nacos image.png

common_log.png 转载务必注明出处:程序员潇然,疯狂的字节X,https://www.crazybytex.com/thread-40-1-1.html

关注下面的标签,发现更多相似文章
    黄小斜学Java

    疯狂的字节X

  • 目前专注于分享Java领域干货,公众号同步更新。原创以及收集整理,把最好的留下。
    包括但不限于JVM、计算机科学、算法、数据库、分布式、Spring全家桶、微服务、高并发、Docker容器、ELK、大数据等相关知识,一起进步,一起成长。
热门推荐
[CXX1300] CMake '3.18.1' was not
[md][CXX1300] CMake '3.18.1' was not found in SDK, PATH, or
[若依]微服务springcloud版新建增添加一个
[md]若依框架是一个比较出名的后台管理系统,有多个不同版本。
解决waiting for all target devices to co
[md]解决Launching app ,waiting for all target devices to co