DATAREST-40 - Added copy constructor to ease setup of HandlerAdapter.
ResourceEnricherInvokingHandlerAdapter now has a copy constructor to allow setting it up from a default RequestMappingHandlerAdapter. The reason we introduce this is that WebMvcConfigurationSupport unfortunately does not allow customizing the handler adapter class to be used as its instantiations is buried in a method with more setup code. With the copy constructor introduced one can simply take the configured instance WebMvcConfigurationSupport provides and pipe it into the custom ResourceEnricherInvokingHandlerAdapter.
This commit is contained in:
@@ -20,6 +20,10 @@ import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.hateoas.ResourceEnricher;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.bind.support.WebBindingInitializer;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
|
||||
import org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
|
||||
@@ -40,6 +44,29 @@ public class ResourceEnricherInvokingHandlerAdapter extends RequestMappingHandle
|
||||
@Autowired(required = false)
|
||||
private List<ResourceEnricher<?>> resourcesEnrichers = new ArrayList<ResourceEnricher<?>>();
|
||||
|
||||
/**
|
||||
* Empty constructor to setup a {@link ResourceEnricherInvokingHandlerAdapter}.
|
||||
*/
|
||||
public ResourceEnricherInvokingHandlerAdapter() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor to copy configuration of {@link HttpMessageConverter}s, {@link WebBindingInitializer}, custom
|
||||
* {@link HandlerMethodArgumentResolver}s and custom {@link HandlerMethodReturnValueHandler}s.
|
||||
*
|
||||
* @param original must not be {@literal null}.
|
||||
*/
|
||||
public ResourceEnricherInvokingHandlerAdapter(RequestMappingHandlerAdapter original) {
|
||||
|
||||
Assert.notNull(original);
|
||||
|
||||
setMessageConverters(original.getMessageConverters());
|
||||
setWebBindingInitializer(original.getWebBindingInitializer());
|
||||
setCustomArgumentResolvers(original.getCustomArgumentResolvers());
|
||||
setCustomReturnValueHandlers(original.getCustomReturnValueHandlers());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#afterPropertiesSet()
|
||||
|
||||
Reference in New Issue
Block a user