|
|
@ -1,20 +1,14 @@ |
|
|
|
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 com.gitee.sop.servercommon.bean.ServiceConfig; |
|
|
|
import com.gitee.sop.servercommon.bean.ServiceConfig; |
|
|
|
import com.gitee.sop.servercommon.interceptor.ServiceContextInterceptor; |
|
|
|
import com.gitee.sop.servercommon.interceptor.ServiceContextInterceptor; |
|
|
|
import com.gitee.sop.servercommon.message.ServiceErrorFactory; |
|
|
|
import com.gitee.sop.servercommon.message.ServiceErrorFactory; |
|
|
|
import com.gitee.sop.servercommon.route.ServiceRouteController; |
|
|
|
import com.gitee.sop.servercommon.route.ServiceRouteController; |
|
|
|
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.ConditionalOnMissingBean; |
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
|
|
|
|
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
import org.springframework.core.env.Environment; |
|
|
|
|
|
|
|
import org.springframework.http.converter.HttpMessageConverter; |
|
|
|
import org.springframework.http.converter.HttpMessageConverter; |
|
|
|
import org.springframework.http.converter.StringHttpMessageConverter; |
|
|
|
import org.springframework.http.converter.StringHttpMessageConverter; |
|
|
|
import org.springframework.scheduling.TaskScheduler; |
|
|
|
|
|
|
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
|
|
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
|
|
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; |
|
|
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; |
|
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
|
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
|
|
@ -22,7 +16,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
|
|
|
import javax.annotation.PostConstruct; |
|
|
|
import javax.annotation.PostConstruct; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @author tanghc |
|
|
|
* @author tanghc |
|
|
@ -31,6 +24,7 @@ import java.util.Map; |
|
|
|
public class ServiceConfiguration implements WebMvcConfigurer { |
|
|
|
public class ServiceConfiguration implements WebMvcConfigurer { |
|
|
|
|
|
|
|
|
|
|
|
public ServiceConfiguration() { |
|
|
|
public ServiceConfiguration() { |
|
|
|
|
|
|
|
System.setProperty("eureka.instance.metadata-map.time.startup", String.valueOf(System.currentTimeMillis())); |
|
|
|
ServiceConfig.getInstance().getI18nModules().add("i18n/isp/bizerror"); |
|
|
|
ServiceConfig.getInstance().getI18nModules().add("i18n/isp/bizerror"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -59,22 +53,6 @@ public class ServiceConfiguration implements WebMvcConfigurer { |
|
|
|
registry.addInterceptor(new ServiceContextInterceptor()); |
|
|
|
registry.addInterceptor(new ServiceContextInterceptor()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@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("server.servlet.context-path"); |
|
|
|
|
|
|
|
// 将context-path信息加入到metadata中
|
|
|
|
|
|
|
|
if (contextPath != null) { |
|
|
|
|
|
|
|
metadata.put("context-path", contextPath); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 在元数据中新增启动时间,不能修改这个值,不然网关拉取接口会有问题
|
|
|
|
|
|
|
|
// 如果没有这个值,网关会忽略这个服务
|
|
|
|
|
|
|
|
metadata.put("time.startup", String.valueOf(System.currentTimeMillis())); |
|
|
|
|
|
|
|
return new NacosWatch(nacosDiscoveryProperties, taskScheduler); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
@Bean |
|
|
|
@ConditionalOnMissingBean |
|
|
|
@ConditionalOnMissingBean |
|
|
|
GlobalExceptionHandler globalExceptionHandler() { |
|
|
|
GlobalExceptionHandler globalExceptionHandler() { |
|
|
|