apollo客户端的使用(二)

新建springboot项目
在这里插入图片描述
依赖:

        <!--apollo装的什么版本这里就用什么版本-->
        <dependency>
            <groupId>com.ctrip.framework.apollo</groupId>
            <artifactId>apollo-client</artifactId>
            <version>1.3.0</version>
        </dependency>
        <dependency>
            <groupId>com.ctrip.framework.apollo</groupId>
            <artifactId>apollo-core</artifactId>
            <version>1.3.0</version>
        </dependency>

1.启动类添加注解:
@MapperScan({“com.ohaotian.tydic.apollotest.dao”})
@Configuration
@EnableApolloConfig

2.由于mapper.xml不是在resources下pom添加:
里添加

        <!--编译不放在resources下的mapper-->
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>

3.application.properties添加:

server.port=8081

#数据源
#spring.datasource.hikari.driver-class-name = com.mysql.jdbc.Driver
#spring.datasource.hikari.jdbc-url = jdbc:mysql://192.168.169.134:3306/student?useUnicode=true&characterEncoding=utf-8
#spring.datasource.hikari.username = root
#spring.datasource.hikari.password = 123456

spring.datasource.url=jdbc:mysql://192.168.169.134:3306/student?useUnicode=true&characterEncoding=utf-8
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=123456

#mapper
mybatis.mapper-locations = classpath:com/ohaotian/tydic/apollotest/mapper/*.xml

4.运行测试一遍,确定配置文件没问题
5.resources中添加:
在这里插入图片描述
内容:
app.id=apollo-test
apollo.env=dev
apollo.meta=http://192.168.169.131:8080

#启动环境配置的方式
#VM: -Denv=dev -Ddev_meta=http://192.168.169.131:8080

6.把配置文件中的配置全部复制到apollo中,并删除配置文件
在这里插入图片描述

7.运行

注:
apollo有缓存配置文件的功能(一旦连接不上apollo,就会用缓存文件,测试的时候,有时没连上apollo,配置项目中的文件,其实是不起作用的,用的是缓存的配置文件)
本地缓存路径
Mac/Linux: /opt/data/{appId}/config-cache
Windows: C:\opt\data{appId}\config-cache

参考:https://blog.csdn.net/weixin_38187317/article/details/84584668

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值