Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
E
event
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
陈世强
event
Commits
dd68590f
提交
dd68590f
authored
12月 31, 2024
作者:
yanxin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
整合nacos和openFeign
上级
95f969c5
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
125 行增加
和
16 行删除
+125
-16
pom.xml
pom.xml
+63
-1
NacosConfig.java
src/main/java/com/zzsn/event/config/NacosConfig.java
+28
-0
application-dev.yml
src/main/resources/application-dev.yml
+0
-4
application-nacos.yml
src/main/resources/application-nacos.yml
+20
-0
application-pro.yml
src/main/resources/application-pro.yml
+0
-4
application-test.yml
src/main/resources/application-test.yml
+0
-4
application.yml
src/main/resources/application.yml
+14
-3
没有找到文件。
pom.xml
浏览文件 @
dd68590f
...
...
@@ -16,6 +16,7 @@
<properties>
<java.version>
1.8
</java.version>
<elasticsearch.version>
7.8.1
</elasticsearch.version>
<nacos.version>
2021.0.1.0
</nacos.version>
</properties>
<dependencies>
<dependency>
...
...
@@ -189,6 +190,31 @@
<version>
${junit.version}
</version>
<scope>
test
</scope>
</dependency>
<!-- nacos 服务的注册发现 -->
<dependency>
<groupId>
com.alibaba.cloud
</groupId>
<artifactId>
spring-cloud-starter-alibaba-nacos-discovery
</artifactId>
<version>
${nacos.version}
</version>
</dependency>
<!-- nacos 配置中心 -->
<dependency>
<groupId>
com.alibaba.cloud
</groupId>
<artifactId>
spring-cloud-starter-alibaba-nacos-config
</artifactId>
<version>
${nacos.version}
</version>
</dependency>
<!-- openfeign依赖 -->
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-openfeign
</artifactId>
<version>
3.1.1
</version>
</dependency>
<!-- openfeign负载均衡依赖 -->
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-loadbalancer
</artifactId>
<version>
3.1.1
</version>
</dependency>
</dependencies>
<build>
...
...
@@ -231,5 +257,41 @@
</releases>
</repository>
</repositories>
<!-- 环境 -->
<profiles>
<!-- 基础单体环境 -->
<profile>
<id>
dev
</id>
<activation>
<!--默认激活配置-->
<activeByDefault>
true
</activeByDefault>
</activation>
<properties>
<!--当前环境-->
<profile.name>
dev
</profile.name>
</properties>
</profile>
<profile>
<id>
test
</id>
<properties>
<!--当前环境-->
<profile.name>
test
</profile.name>
</properties>
</profile>
<profile>
<id>
pro
</id>
<properties>
<!--当前环境-->
<profile.name>
pro
</profile.name>
</properties>
</profile>
<!-- 整合nacos作为配置中心,注册中心 -->
<profile>
<id>
nacos
</id>
<properties>
<!--当前环境-->
<profile.name>
nacos
</profile.name>
</properties>
</profile>
</profiles>
</project>
src/main/java/com/zzsn/event/config/NacosConfig.java
0 → 100644
浏览文件 @
dd68590f
package
com
.
zzsn
.
event
.
config
;
import
com.alibaba.nacos.api.exception.NacosException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.cloud.client.discovery.EnableDiscoveryClient
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.context.annotation.Configuration
;
import
javax.annotation.PostConstruct
;
//根据当前环境判断是否启用nacos配置
@Configuration
@ConditionalOnProperty
(
prefix
=
"spring.profiles"
,
value
=
"active"
,
havingValue
=
"nacos"
)
@EnableDiscoveryClient
@EnableFeignClients
(
basePackages
=
"com.zzsn.event.feign.api"
)
public
class
NacosConfig
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
NacosConfig
.
class
);
@Value
(
"${spring.application.name}"
)
private
String
serviceName
;
@PostConstruct
public
void
registerInstance
()
throws
NacosException
{
log
.
info
(
"nacos服务注册成功:{}"
,
serviceName
);
}
}
src/main/resources/application-dev.yml
浏览文件 @
dd68590f
server
:
port
:
1688
servlet
:
context-path
:
/event
spring
:
servlet
:
multipart
:
...
...
src/main/resources/application-nacos.yml
0 → 100644
浏览文件 @
dd68590f
spring
:
config
:
# nacos配置中心必须加此项配置,否则会因为配置文件加载顺序原因导致配置中心配置无效
import
:
"
optional:nacos:${spring.application.name}.${spring.cloud.nacos.config.file-extension}?group=${spring.cloud.nacos.config.group}"
cloud
:
nacos
:
# nacos 服务注册
discovery
:
enabled
:
true
server-addr
:
nacos:8848
namespace
:
# 命名空间
# nacos 配置中心
config
:
username
:
nacos
password
:
nacos
server-addr
:
nacos:8848
namespace
:
# 命名空间
group
:
clb-service
prefix
:
${spring.application.name}
# 配置前缀,默认是应用名
file-extension
:
yaml
src/main/resources/application-pro.yml
浏览文件 @
dd68590f
server
:
port
:
1688
servlet
:
context-path
:
/event
spring
:
servlet
:
multipart
:
...
...
src/main/resources/application-test.yml
浏览文件 @
dd68590f
server
:
port
:
1688
servlet
:
context-path
:
/event
spring
:
servlet
:
multipart
:
...
...
src/main/resources/application.yml
浏览文件 @
dd68590f
server
:
port
:
1688
servlet
:
context-path
:
/event
spring
:
profiles
:
# active: dev
active
:
pro
\ No newline at end of file
active
:
@
profile.name@
application
:
name
:
event
main
:
allow-bean-definition-overriding
:
true
cloud
:
nacos
:
discovery
:
#默认禁用nacos注册发现
enabled
:
false
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论