spring(不是springboot)集成apllo方案

现在到处都是基于 springboot 的微服务项目。
不巧手头碰到了一个 spring 的项目,打war包直接放到tomcat中启动的。
现在要将apollo集成进来,要求 Access Key 不可以放在properties 配置文件中,要统一使用apollo来管理。


步骤如下:
1.首先 spring 的 pom.xml 文件中加入apollo的依赖

        <dependency>
			<groupId>com.ctrip.framework.apollo</groupId>
			<artifactId>apollo-client</artifactId>
			<version>1.5.1</version>
		</dependency>
		<dependency>
            <groupId>com.ctrip.framework.apollo</groupId>
            <artifactId>apollo-core</artifactId>
            <version>1.5.1</version>
        </dependency>

2.在项目的 applicationContext.xml 的 <beans> 标签中加入apollo相关内容:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:apollo="http://www.ctrip.com/schema/apollo"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    						 http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd
                          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
                          http://www.ctrip.com/schema/apollo http://www.ctrip.com/schema/apollo.xsd"
       default-autowire="byName">

其中 xmlns:apollo="http://www.ctrip.com/schema/apollo"
http://www.ctrip.com/schema/apollo http://www.ctrip.com/schema/apollo.xsd
为apollo相关配置内容。

3. 在applicationContext.xml 中 加入apollo的配置标签

<apollo:config/>

4. 新增相关配置
① 在src/main/resource 下新建 META-INF 文件夹,在其中添加 app.properties 文件。
文件内容为:app.id=对应的appid

app.id=com.some.company.project

5.多环境配置
如果只用于一个环境,那么在上面的app.properties中增加:
apollo.meta=http://xxx.xx.xx.xx:xxxx
即可。
如果有多个环境,比如dev、fat、uat、pro,那么推荐两种方式:

方式一:

在 tomat的bin目录下,找到 catalina.sh,在其中的 JAVA_OPTS 配置中增加如下内容:

JAVA_OPTS=" -Dapollo.configService=http://xx.xxx.xxx.xx:xxxx "

也可以在bin目录下创建一个名为setenv.sh的文件,将上述配置写在这里面。

方式二:

在src/main/resource 下新建 apollo-env.properties (注意不是MEAT-INF,而是其上一层)
在这里插入图片描述

文件内容为:

dev.meta=http://1.1.1.1:8080
fat.meta=http://xx.xxx.xx.xx:8080
uat.meta=http://apollo.uat.xxx.com
pro.meta=http://apollo.xxx.com

然后在服务器上创建:/opt/settings/server.properties
并在其中写明当前的环境名:

env=FAT

即可。


上述内容,在apollo的文档中有描述,文档链接为:
Apollo 使用文档

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值