Commit ecedfbb7 by Nepxion

重构类结构

parent 5f29ed3b
......@@ -11,8 +11,6 @@ package com.nepxion.discovery.plugin.framework.context;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.ResolvableType;
......@@ -24,9 +22,6 @@ public class PluginContextAware implements ApplicationContextAware {
private ApplicationContext applicationContext;
private Environment environment;
@Autowired
private ServerProperties serverProperties;
@Override
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
......@@ -89,14 +84,6 @@ public class PluginContextAware implements ApplicationContextAware {
return environment;
}
public String getAddress() {
return serverProperties.getAddress().getHostAddress();
}
public int getPort() {
return serverProperties.getPort();
}
public String getServiceId() {
return environment.getProperty(PluginConstant.SPRING_APPLICATION_NAME);
}
......
......@@ -23,6 +23,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -37,7 +38,6 @@ import com.nepxion.discovery.plugin.framework.context.PluginContainerInitialized
import com.nepxion.discovery.plugin.framework.context.PluginContextAware;
import com.nepxion.discovery.plugin.framework.entity.RouterEntity;
import com.nepxion.discovery.plugin.framework.exception.PluginException;
import com.nepxion.eventbus.util.HostUtil;
@RestController
@Api(tags = { "路由接口" })
......@@ -57,6 +57,9 @@ public class RouterController {
@Autowired
private DiscoveryClient discoveryClient;
@Autowired
private Registration registration;
@RequestMapping(path = "/services", method = RequestMethod.GET)
@ApiOperation(value = "获取服务注册中心所有服务列表", notes = "", response = List.class, httpMethod = "GET")
public List<String> services() {
......@@ -104,8 +107,10 @@ public class RouterController {
public RouterEntity getRouterEntity() {
String serviceId = pluginContextAware.getServiceId();
String version = pluginAdapter.getVersion();
String host = HostUtil.getLocalhost();
int port = pluginContainerInitializedHandler.getPort();
String host = pluginAdapter.getIpAddress(registration);
int port = pluginAdapter.getPort(registration);
// String host = HostUtil.getLocalhost();
// int port = pluginContainerInitializedHandler.getPort();
RouterEntity routerEntity = new RouterEntity();
routerEntity.setServiceId(serviceId);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment