pom.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
ycl-platform/src/main/java/com/ycl/PlatformApplication.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
ycl-platform/src/main/java/com/ycl/config/feign/FeignConfiguration.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
ycl-platform/src/main/java/com/ycl/config/feign/FeignGlobalConfiguration.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
ycl-platform/src/main/java/com/ycl/config/feign/UnderlineQueryEncoder.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
ycl-platform/src/main/java/com/ycl/remote/service/CityPlatformService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
ycl-platform/src/main/resources/logback.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
pom.xml
@@ -181,11 +181,11 @@ <version>1.2.73</version> </dependency> <!-- <dependency>--> <!-- <groupId>org.springframework.cloud</groupId>--> <!-- <artifactId>spring-cloud-starter-openfeign</artifactId>--> <!-- <version>2.2.7.RELEASE</version>--> <!-- </dependency>--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> <version>3.1.3</version> </dependency> </dependencies> </project> ycl-platform/src/main/java/com/ycl/PlatformApplication.java
@@ -3,7 +3,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; //import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableAspectJAutoProxy; @@ -20,7 +20,7 @@ @EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true) @EnableAsync(proxyTargetClass = true) @EnableScheduling //@EnableFeignClients @EnableFeignClients @EnableTransactionManagement(proxyTargetClass = true) @SpringBootApplication public class PlatformApplication { ycl-platform/src/main/java/com/ycl/config/feign/FeignConfiguration.java
@@ -1,22 +1,22 @@ package com.ycl.config.feign; //import feign.Feign; //import feign.Logger; //import feign.Retryer; import feign.Feign; import feign.Logger; import feign.Retryer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class FeignConfiguration { // @Bean // Logger.Level feignLoggerLevel() { // return Logger.Level.FULL; // } // // @Bean // public Feign.Builder feignBuilder() { // return Feign.builder() // .queryMapEncoder(new UnderlineQueryEncoder()) // .retryer(Retryer.NEVER_RETRY); // } @Bean Logger.Level feignLoggerLevel() { return Logger.Level.FULL; } @Bean public Feign.Builder feignBuilder() { return Feign.builder() .queryMapEncoder(new UnderlineQueryEncoder()) .retryer(Retryer.NEVER_RETRY); } } ycl-platform/src/main/java/com/ycl/config/feign/FeignGlobalConfiguration.java
@@ -1,9 +1,9 @@ package com.ycl.config.feign; //import feign.codec.Decoder; //import org.springframework.beans.factory.ObjectFactory; //import org.springframework.boot.autoconfigure.http.HttpMessageConverters; //import org.springframework.cloud.openfeign.support.SpringDecoder; import feign.codec.Decoder; import org.springframework.beans.factory.ObjectFactory; import org.springframework.boot.autoconfigure.http.HttpMessageConverters; import org.springframework.cloud.openfeign.support.SpringDecoder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -11,10 +11,10 @@ public class FeignGlobalConfiguration { // @Bean // public Decoder feignDecoder(){ // MessageConverter converter = new MessageConverter(); // ObjectFactory<HttpMessageConverters> objectFactory = () -> new HttpMessageConverters(converter); // return new SpringDecoder(objectFactory); // } @Bean public Decoder feignDecoder(){ MessageConverter converter = new MessageConverter(); ObjectFactory<HttpMessageConverters> objectFactory = () -> new HttpMessageConverters(converter); return new SpringDecoder(objectFactory); } } ycl-platform/src/main/java/com/ycl/config/feign/UnderlineQueryEncoder.java
@@ -1,9 +1,9 @@ package com.ycl.config.feign; import com.ycl.utils.StringUtils; //import feign.Param; //import feign.QueryMapEncoder; //import feign.codec.EncodeException; import feign.Param; import feign.QueryMapEncoder; import feign.codec.EncodeException; import java.beans.IntrospectionException; import java.beans.Introspector; @@ -12,60 +12,59 @@ import java.lang.reflect.Method; import java.util.*; public class UnderlineQueryEncoder{ // implements QueryMapEncoder { // private final Map<Class<?>, ObjectParamMetadata> classToMetadata = // new HashMap(); // // @Override // public Map<String, Object> encode(Object object) throws EncodeException { // try { // ObjectParamMetadata metadata = getMetadata(object.getClass()); // Map<String, Object> propertyNameToValue = new HashMap<String, Object>(); // for (PropertyDescriptor pd : metadata.objectProperties) { // Method method = pd.getReadMethod(); // Object value = method.invoke(object); // if (value != null && value != object) { // Param alias = method.getAnnotation(Param.class); // String name = alias != null ? alias.value() : pd.getName(); // propertyNameToValue.put(StringUtils.camelToUnderlineLowerCase(name), value); // } // } // return propertyNameToValue; // } catch (IllegalAccessException | IntrospectionException | InvocationTargetException e) { // throw new EncodeException("Failure encoding object into query map", e); // } // } // // private ObjectParamMetadata getMetadata(Class<?> objectType) throws IntrospectionException { // ObjectParamMetadata metadata = classToMetadata.get(objectType); // if (metadata == null) { // metadata = ObjectParamMetadata.parseObjectType(objectType); // classToMetadata.put(objectType, metadata); // } // return metadata; // } // // private static class ObjectParamMetadata { // // private final List<PropertyDescriptor> objectProperties; // // private ObjectParamMetadata(List<PropertyDescriptor> objectProperties) { // this.objectProperties = Collections.unmodifiableList(objectProperties); // } // // private static ObjectParamMetadata parseObjectType(Class<?> type) // throws IntrospectionException { // List<PropertyDescriptor> properties = new ArrayList<PropertyDescriptor>(); // // for (PropertyDescriptor pd : Introspector.getBeanInfo(type).getPropertyDescriptors()) { // boolean isGetterMethod = pd.getReadMethod() != null && !"class".equals(pd.getName()); // if (isGetterMethod) { // properties.add(pd); // } // } // // return new ObjectParamMetadata(properties); // } // } public class UnderlineQueryEncoder implements QueryMapEncoder { private final Map<Class<?>, ObjectParamMetadata> classToMetadata = new HashMap(); @Override public Map<String, Object> encode(Object object) throws EncodeException { try { ObjectParamMetadata metadata = getMetadata(object.getClass()); Map<String, Object> propertyNameToValue = new HashMap<String, Object>(); for (PropertyDescriptor pd : metadata.objectProperties) { Method method = pd.getReadMethod(); Object value = method.invoke(object); if (value != null && value != object) { Param alias = method.getAnnotation(Param.class); String name = alias != null ? alias.value() : pd.getName(); propertyNameToValue.put(StringUtils.camelToUnderlineLowerCase(name), value); } } return propertyNameToValue; } catch (IllegalAccessException | IntrospectionException | InvocationTargetException e) { throw new EncodeException("Failure encoding object into query map", e); } } private ObjectParamMetadata getMetadata(Class<?> objectType) throws IntrospectionException { ObjectParamMetadata metadata = classToMetadata.get(objectType); if (metadata == null) { metadata = ObjectParamMetadata.parseObjectType(objectType); classToMetadata.put(objectType, metadata); } return metadata; } private static class ObjectParamMetadata { private final List<PropertyDescriptor> objectProperties; private ObjectParamMetadata(List<PropertyDescriptor> objectProperties) { this.objectProperties = Collections.unmodifiableList(objectProperties); } private static ObjectParamMetadata parseObjectType(Class<?> type) throws IntrospectionException { List<PropertyDescriptor> properties = new ArrayList<PropertyDescriptor>(); for (PropertyDescriptor pd : Introspector.getBeanInfo(type).getPropertyDescriptors()) { boolean isGetterMethod = pd.getReadMethod() != null && !"class".equals(pd.getName()); if (isGetterMethod) { properties.add(pd); } } return new ObjectParamMetadata(properties); } } } ycl-platform/src/main/java/com/ycl/remote/service/CityPlatformService.java
@@ -1,7 +1,7 @@ package com.ycl.remote.service; import com.ycl.remote.dto.*; //import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -12,7 +12,7 @@ * @author: AI * @date: 2022-09-28 15:40 **/ //@FeignClient(url = "http://10.53.139.176:81/api", name = "cityApi") @FeignClient(url = "http://10.53.139.176:81/api", name = "cityApi") public interface CityPlatformService { /** ycl-platform/src/main/resources/logback.xml
@@ -107,25 +107,6 @@ <appender-ref ref="errorLog" /> </root> </springProfile> <springProfile name="test"> <!--打印SQL--> <logger name="java.sql.Connection" level="DEBUG" /> <logger name="java.sql.Statement" level="DEBUG" /> <logger name="java.sql.PreparedStatement" level="DEBUG" /> <logger name="com.ycl.component" level="error" /> <logger name="com.ycl" level="debug" > <appender-ref ref="normalLog" /> <appender-ref ref="errorLog" /> </logger> <root level="info"> <appender-ref ref="Console" /> <appender-ref ref="normalLog" /> <appender-ref ref="errorLog" /> </root> </springProfile> <springProfile name="pro"> <!--打印SQL-->