restTemplate Bean注入

main
yangmengchuan 2 days ago
parent 6a6095784b
commit 8b3f7e8647
  1. 6
      src/main/java/com/keyware/htey/config/HertzServerConfig.java
  2. 2
      src/main/java/com/keyware/htey/controller/hertz/HertzController.java

@ -3,7 +3,9 @@ package com.keyware.htey.config;
import lombok.Data; import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
/** /**
* 监控三方服务配置 * 监控三方服务配置
@ -12,6 +14,10 @@ import org.springframework.context.annotation.Configuration;
@Configuration @Configuration
@ConfigurationProperties(prefix = "hertz") @ConfigurationProperties(prefix = "hertz")
public class HertzServerConfig { public class HertzServerConfig {
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
/** /**
* 服务地址 * 服务地址
*/ */

@ -30,8 +30,6 @@ public class HertzController {
@ApiResponse(responseCode = "200", description = "系统监视") @ApiResponse(responseCode = "200", description = "系统监视")
public Object selectAll() throws IOException { public Object selectAll() throws IOException {
Map<String, Object> monitorData = hertzBeatClient.getMonitorData(); Map<String, Object> monitorData = hertzBeatClient.getMonitorData();
// 将 JSON 字符串转换为 Map
System.out.println("1");
return monitorData; return monitorData;
} }
} }

Loading…
Cancel
Save