eureka
tanghc 4 years ago
parent b05e0409da
commit 5e2683d88b
  1. 26
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/ServiceConfiguration.java
  2. 1
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/SpringmvcConfiguration.java

@ -1,16 +1,6 @@
package com.gitee.sop.servercommon.configuration; package com.gitee.sop.servercommon.configuration;
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import com.alibaba.cloud.nacos.discovery.NacosWatch;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.TaskScheduler;
import java.util.Map;
/** /**
* @author tanghc * @author tanghc
@ -18,20 +8,4 @@ import java.util.Map;
@Slf4j @Slf4j
public class ServiceConfiguration extends SpringmvcConfiguration { public class ServiceConfiguration extends SpringmvcConfiguration {
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty("spring.cloud.nacos.discovery.server-addr")
public NacosWatch nacosWatch(NacosDiscoveryProperties nacosDiscoveryProperties, ObjectProvider<TaskScheduler> taskScheduler, Environment environment) {
Map<String, String> metadata = nacosDiscoveryProperties.getMetadata();
String contextPath = environment.getProperty(METADATA_SERVER_CONTEXT_PATH);
// 将context-path信息加入到metadata中
if (contextPath != null) {
metadata.put(METADATA_SERVER_CONTEXT_PATH, contextPath);
}
// 在元数据中新增启动时间,不能修改这个值,不然网关拉取接口会有问题
// 如果没有这个值,网关会忽略这个服务
metadata.put("server.startup-time", String.valueOf(System.currentTimeMillis()));
return new NacosWatch(nacosDiscoveryProperties, taskScheduler);
}
} }

@ -26,6 +26,7 @@ public class SpringmvcConfiguration implements WebMvcConfigurer {
public static final String METADATA_SERVER_CONTEXT_PATH = "server.servlet.context-path"; public static final String METADATA_SERVER_CONTEXT_PATH = "server.servlet.context-path";
public SpringmvcConfiguration() { public SpringmvcConfiguration() {
System.setProperty("eureka.instance.metadata-map.server.startup-time", String.valueOf(System.currentTimeMillis()));
ServiceConfig.getInstance().getI18nModules().add("i18n/isp/bizerror"); ServiceConfig.getInstance().getI18nModules().add("i18n/isp/bizerror");
} }

Loading…
Cancel
Save