Nacos已注册的服务不能使用服务名访问
Closed this issue · 2 comments
wosuanle commented
consumer依赖增加了一下两个依赖
org.springframework.cloud
spring-cloud-loadbalancer
com.alibaba.cloud
spring-cloud-starter-alibaba-nacos-discovery
org.springframework.cloud
spring-cloud-starter-netflix-ribbon
访问报错:java.net.UnknownHostException: nacos-discoveryC
父项目使用的springCloud版本:4.1.3,springCloudAlibaba版本:2023.0.1.0
请各位各位大佬帮帮小白我把,求求啦
wosuanle commented
文章依赖的<>没有显示出来
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-loadbalancer</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</exclusion>
</exclusions>
</dependency>
wosuanle commented
已解决,导致原因不明,解决办法如下:
父项目依赖:
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-build</artifactId>
<version>4.1.3</version>
<relativePath/>
</parent>
<properties>
<!-- Spring Cloud -->
<spring.cloud.version>2023.0.3</spring.cloud.version>
<!-- Spring Boot -->
<spring-boot.version>3.2.9</spring-boot.version>
</properties>
<dependencyManagement>
<dependencies>
<!-- Spring Dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring.cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2023.0.1.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
当前consumer使用负载均衡并拉取nacos配置中心配置的项目依赖:
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<exclusions>
<exclusion>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-loadbalancer</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>compile</scope>
</dependency>
项目配置文件:
spring:
config:
import: #springcloud禁用了bootstrap配置文件,官方代码里增加了改配置请求配置中心文件,
- nacos:nacos-consumer.properties?refreshEnabled=true&group=DEFAULT_GROUP
application:
name: nacos-consumer
cloud:
loadbalancer:
ribbon:
enabled: false
nacos:
enabled: true
nacos:
config:
import-check:
enabled: false
serverAddr: 127.0.0.1:8848
username: 'nacos'
password: 'nacos'
discovery:
serverAddr: 127.0.0.1:8848
username: 'nacos'
password: 'nacos'
server:
port: 8888
management:
endpoint:
health:
show-details: always
endpoints:
web:
exposure:
include: '*'
logging:
level:
com.alibaba.cloud.nacos.configdata: debug
service-url:
nacos-discovery: http://nacos-discovery