nacos服务发现,但是写了一个消费端和服务端,消费端不能通过服务名访问到服务,总是报错,说 java.net.UnknownHostException: nacos-payment
消费端:配置没问题
80pom
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
</dependencies>
80端口消费者 yml
server:
port: 80
spring:
application:
name: nacos-order-80
cloud:
nacos:
discovery:
server-addr: localhost:8848
service-url:
payment: http://nacos-payment
80端口启动类
@EnableDiscoveryClient
@SpringBootApplication
public class OrderApplication {
public static void main(String[] args) {
SpringApplication.run(OrderApplication.class,args);
}
}
80配置类
@Configuration
public class OrderConfig {
@Bean
@LoadBalanced
public RestTemplate getRestTemplate(){
return new RestTemplate();
}
}
80控制类
@RestController
public class OrderController {
@Value("${service-url.payment}")
private String serviceable;
@Autowired
private RestTemplate restTemplate;
@GetMapping(path = "/get")
public String payment(){
return restTemplate.getForObject(serviceable +"/nacos/get",String.class);
}
}
9001端口服务端yml
server:
port: 9001
spring:
application:
name: nacos-payment
cloud:
nacos:
discovery:
server-addr: localhost:8848
management:
endpoints:
web:
exposure:
include: '*'
9001端口的控制类启动类就不粘了
问题是这样的,配置如上,没有问题应该,服务也注册进去了但是,80端口请qiu服务失败
请大da帮 bang我,好不容易把微服务顶到 阿里巴巴这里了,结果碰到了一个想破脑袋也没ok的坑。