工程结构
ApplicationContextConfig
@Configuration
public class ApplicationContextConfig {
@Bean
@LoadBalanced
public RestTemplate restTemplate ( )
{
return new RestTemplate ( ) ;
}
}
OrderController
@RestController
@Slf4j
public class OrderZKContorller {
public static final String INVOKE_URL= "http://cloud-provider-payment" ;
@Resource
private RestTemplate restTemplate;
@GetMapping ( value= "/consumer/payment/zk" )
public String paymentInfo ( ) {
String result = restTemplate. getForObject ( INVOKE_URL+ "/payment/zk" , String. class ) ;
return result;
}
}
yml
server:
port: 80
spring:
application:
name: cloud- consumer- order
datasource:
type: com. alibaba. druid. pool. DruidDataSource
driver- class - name: com. mysql. jdbc. Driver
# 防止报SSL安全加固未禁用也未指定的错误
url: jdbc: mysql: / / 192.168 .101 .7 : 3306 / cloudedu? useunicode= true & characterEncoding= utf- 8 & useSSL= false
username: root
password: 123
cloud:
zookeeper:
connect- string: 192.168 .101 .7 : 2181
mybatis:
mapperLocations: classpath: mapper
运行后查看zk中的services
进一步测试