Commit 6e078a88 by Spencer Gibb

make messageConverters lazy in SpringDecoder and SpringEncoder

fixes gh-129
parent 8fb85f26
......@@ -258,6 +258,11 @@
<artifactId>bootstrap</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
</dependencies>
</dependencyManagement>
......
......@@ -135,6 +135,10 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
......
......@@ -17,6 +17,8 @@ import feign.Response;
import feign.codec.DecodeException;
import feign.codec.Decoder;
import javax.inject.Provider;
import static org.springframework.cloud.netflix.feign.FeignUtils.getHttpHeaders;
/**
......@@ -25,7 +27,7 @@ import static org.springframework.cloud.netflix.feign.FeignUtils.getHttpHeaders;
public class SpringDecoder implements Decoder {
@Autowired
HttpMessageConverters messageConverters;
Provider<HttpMessageConverters> messageConverters;
public SpringDecoder() {
}
......@@ -35,7 +37,7 @@ public class SpringDecoder implements Decoder {
if (type instanceof Class || type instanceof ParameterizedType) {
@SuppressWarnings({ "unchecked", "rawtypes" })
HttpMessageConverterExtractor<?> extractor = new HttpMessageConverterExtractor(
type, messageConverters.getConverters());
type, messageConverters.get().getConverters());
return extractor.extractData(new FeignResponseAdapter(response));
}
......
......@@ -15,6 +15,7 @@ import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import javax.inject.Provider;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
......@@ -29,7 +30,7 @@ public class SpringEncoder implements Encoder {
private static final Logger logger = LoggerFactory.getLogger(SpringEncoder.class);
@Autowired
HttpMessageConverters messageConverters;
Provider<HttpMessageConverters> messageConverters;
public SpringEncoder() {
}
......@@ -48,7 +49,7 @@ public class SpringEncoder implements Encoder {
requestContentType = MediaType.valueOf(type);
}
for (HttpMessageConverter<?> messageConverter : messageConverters.getConverters()) {
for (HttpMessageConverter<?> messageConverter : messageConverters.get().getConverters()) {
if (messageConverter.canWrite(requestType, requestContentType)) {
if (logger.isDebugEnabled()) {
if (requestContentType != null) {
......
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