Commit 3893383c authored by Phillip Webb's avatar Phillip Webb

Merge branch '1.5.x'

parents d1727f25 5703fb15
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -240,18 +240,22 @@ public class EndpointWebMvcHypermediaManagementContextConfiguration { ...@@ -240,18 +240,22 @@ public class EndpointWebMvcHypermediaManagementContextConfiguration {
for (RequestMappingHandlerAdapter handlerAdapter : this.handlerAdapters) { for (RequestMappingHandlerAdapter handlerAdapter : this.handlerAdapters) {
for (HttpMessageConverter<?> messageConverter : handlerAdapter for (HttpMessageConverter<?> messageConverter : handlerAdapter
.getMessageConverters()) { .getMessageConverters()) {
if (messageConverter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) { configureHttpMessageConverter(messageConverter);
List<MediaType> supportedMediaTypes = new ArrayList<MediaType>(
messageConverter.getSupportedMediaTypes());
supportedMediaTypes
.add(ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON);
((AbstractHttpMessageConverter<?>) messageConverter)
.setSupportedMediaTypes(supportedMediaTypes);
}
} }
} }
} }
private void configureHttpMessageConverter(
HttpMessageConverter<?> messageConverter) {
if (messageConverter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) {
List<MediaType> supportedMediaTypes = new ArrayList<MediaType>(
messageConverter.getSupportedMediaTypes());
supportedMediaTypes.add(ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON);
((AbstractHttpMessageConverter<?>) messageConverter)
.setSupportedMediaTypes(supportedMediaTypes);
}
}
@Override @Override
public boolean supports(MethodParameter returnType, public boolean supports(MethodParameter returnType,
Class<? extends HttpMessageConverter<?>> converterType) { Class<? extends HttpMessageConverter<?>> converterType) {
......
...@@ -44,7 +44,6 @@ import org.springframework.web.bind.annotation.RequestMethod; ...@@ -44,7 +44,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
/** /**
* Alias for {@link RequestMapping#value}. * Alias for {@link RequestMapping#value}.
*
* @return the value * @return the value
*/ */
@AliasFor(annotation = RequestMapping.class) @AliasFor(annotation = RequestMapping.class)
......
...@@ -22,6 +22,7 @@ import org.springframework.http.MediaType; ...@@ -22,6 +22,7 @@ import org.springframework.http.MediaType;
* {@link MediaType MediaTypes} that can be consumed and produced by Actuator endpoints. * {@link MediaType MediaTypes} that can be consumed and produced by Actuator endpoints.
* *
* @author Andy Wilkinson * @author Andy Wilkinson
* @since 1.5.0
*/ */
public final class ActuatorMediaTypes { public final class ActuatorMediaTypes {
......
...@@ -48,7 +48,6 @@ import org.springframework.web.bind.annotation.RequestMethod; ...@@ -48,7 +48,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
/** /**
* Alias for {@link RequestMapping#value}. * Alias for {@link RequestMapping#value}.
*
* @return the value * @return the value
*/ */
@AliasFor(annotation = RequestMapping.class) @AliasFor(annotation = RequestMapping.class)
......
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
/* /*
* Copyright 2012-2015 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -17,9 +17,8 @@ ...@@ -17,9 +17,8 @@
package org.springframework.boot.autoconfigure.hateoas; package org.springframework.boot.autoconfigure.hateoas;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
...@@ -63,28 +62,32 @@ public class HypermediaHttpMessageConverterConfiguration { ...@@ -63,28 +62,32 @@ public class HypermediaHttpMessageConverterConfiguration {
private volatile BeanFactory beanFactory; private volatile BeanFactory beanFactory;
@PostConstruct @PostConstruct
public void customizedSupportedMediaTypes() { public void configureHttpMessageConverters() {
if (this.beanFactory instanceof ListableBeanFactory) { if (this.beanFactory instanceof ListableBeanFactory) {
Map<String, RequestMappingHandlerAdapter> handlerAdapters = ((ListableBeanFactory) this.beanFactory) configureHttpMessageConverters(((ListableBeanFactory) this.beanFactory)
.getBeansOfType(RequestMappingHandlerAdapter.class); .getBeansOfType(RequestMappingHandlerAdapter.class).values());
for (Entry<String, RequestMappingHandlerAdapter> entry : handlerAdapters }
.entrySet()) { }
RequestMappingHandlerAdapter handlerAdapter = entry.getValue();
for (HttpMessageConverter<?> converter : handlerAdapter private void configureHttpMessageConverters(
.getMessageConverters()) { Collection<RequestMappingHandlerAdapter> handlerAdapters) {
if (converter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) { for (RequestMappingHandlerAdapter handlerAdapter : handlerAdapters) {
List<MediaType> supportedMediaTypes = new ArrayList<MediaType>( for (HttpMessageConverter<?> messageConverter : handlerAdapter
converter.getSupportedMediaTypes()); .getMessageConverters()) {
if (!supportedMediaTypes configureHttpMessageConverter(messageConverter);
.contains(MediaType.APPLICATION_JSON)) { }
supportedMediaTypes.add(MediaType.APPLICATION_JSON); }
} }
((AbstractHttpMessageConverter<?>) converter)
.setSupportedMediaTypes(supportedMediaTypes);
}
}
private void configureHttpMessageConverter(HttpMessageConverter<?> converter) {
if (converter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) {
List<MediaType> supportedMediaTypes = new ArrayList<MediaType>(
converter.getSupportedMediaTypes());
if (!supportedMediaTypes.contains(MediaType.APPLICATION_JSON)) {
supportedMediaTypes.add(MediaType.APPLICATION_JSON);
} }
((AbstractHttpMessageConverter<?>) converter)
.setSupportedMediaTypes(supportedMediaTypes);
} }
} }
......
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
/* /*
* Copyright 2012-2013 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
...@@ -30,7 +30,7 @@ import org.springframework.boot.autoconfigure.ImportAutoConfiguration; ...@@ -30,7 +30,7 @@ import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
* tests. Most tests should consider using {@link DataMongoTest @DataMongoTest} rather * tests. Most tests should consider using {@link DataMongoTest @DataMongoTest} rather
* than using this annotation directly. * than using this annotation directly.
* *
* @author Michael J. Simons * @author Michael Simons
* @since 1.5.0 * @since 1.5.0
* @see DataMongoTest * @see DataMongoTest
*/ */
...@@ -40,4 +40,5 @@ import org.springframework.boot.autoconfigure.ImportAutoConfiguration; ...@@ -40,4 +40,5 @@ import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
@Inherited @Inherited
@ImportAutoConfiguration @ImportAutoConfiguration
public @interface AutoConfigureDataMongo { public @interface AutoConfigureDataMongo {
} }
...@@ -35,8 +35,8 @@ import org.springframework.test.context.BootstrapWith; ...@@ -35,8 +35,8 @@ import org.springframework.test.context.BootstrapWith;
/** /**
* Annotation that can be used in combination with {@code @RunWith(SpringRunner.class)} * Annotation that can be used in combination with {@code @RunWith(SpringRunner.class)}
* for a typical MongoDB test. Can be used when a test focuses * for a typical MongoDB test. Can be used when a test focuses <strong>only</strong> on
* <strong>only</strong> on MongoDB components. * MongoDB components.
* <p> * <p>
* Using this annotation will disable full auto-configuration and instead apply only * Using this annotation will disable full auto-configuration and instead apply only
* configuration relevant to MongoDB tests. * configuration relevant to MongoDB tests.
...@@ -44,7 +44,7 @@ import org.springframework.test.context.BootstrapWith; ...@@ -44,7 +44,7 @@ import org.springframework.test.context.BootstrapWith;
* By default, tests annotated with {@code @DataMongoTest} will use an embedded in-memory * By default, tests annotated with {@code @DataMongoTest} will use an embedded in-memory
* MongoDB process (if available). * MongoDB process (if available).
* *
* @author Michael J. Simons * @author Michael Simons
* @author Stephane Nicoll * @author Stephane Nicoll
* @since 1.5.0 * @since 1.5.0
*/ */
...@@ -62,9 +62,8 @@ public @interface DataMongoTest { ...@@ -62,9 +62,8 @@ public @interface DataMongoTest {
/** /**
* Determines if default filtering should be used with * Determines if default filtering should be used with
* {@link SpringBootApplication @SpringBootApplication}. By default no beans * {@link SpringBootApplication @SpringBootApplication}. By default no beans are
* are included. * included.
*
* @see #includeFilters() * @see #includeFilters()
* @see #excludeFilters() * @see #excludeFilters()
* @return if default filters should be used * @return if default filters should be used
...@@ -72,17 +71,15 @@ public @interface DataMongoTest { ...@@ -72,17 +71,15 @@ public @interface DataMongoTest {
boolean useDefaultFilters() default true; boolean useDefaultFilters() default true;
/** /**
* A set of include filters which can be used to add otherwise filtered * A set of include filters which can be used to add otherwise filtered beans to the
* beans to the application context. * application context.
*
* @return include filters to apply * @return include filters to apply
*/ */
Filter[] includeFilters() default {}; Filter[] includeFilters() default {};
/** /**
* A set of exclude filters which can be used to filter beans that would * A set of exclude filters which can be used to filter beans that would otherwise be
* otherwise be added to the application context. * added to the application context.
*
* @return exclude filters to apply * @return exclude filters to apply
*/ */
Filter[] excludeFilters() default {}; Filter[] excludeFilters() default {};
...@@ -93,4 +90,5 @@ public @interface DataMongoTest { ...@@ -93,4 +90,5 @@ public @interface DataMongoTest {
*/ */
@AliasFor(annotation = ImportAutoConfiguration.class, attribute = "exclude") @AliasFor(annotation = ImportAutoConfiguration.class, attribute = "exclude")
Class<?>[] excludeAutoConfiguration() default {}; Class<?>[] excludeAutoConfiguration() default {};
} }
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -30,7 +30,7 @@ import org.springframework.core.type.classreading.MetadataReaderFactory; ...@@ -30,7 +30,7 @@ import org.springframework.core.type.classreading.MetadataReaderFactory;
/** /**
* {@link TypeExcludeFilter} for {@link DataMongoTest @DataMongoTest}. * {@link TypeExcludeFilter} for {@link DataMongoTest @DataMongoTest}.
* *
* @author Michael J. Simons * @author Michael Simons
*/ */
class DataMongoTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter { class DataMongoTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter {
...@@ -49,12 +49,12 @@ class DataMongoTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter ...@@ -49,12 +49,12 @@ class DataMongoTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter
@Override @Override
protected Filter[] getFilters(final FilterType type) { protected Filter[] getFilters(final FilterType type) {
switch (type) { switch (type) {
case INCLUDE: case INCLUDE:
return this.annotation.includeFilters(); return this.annotation.includeFilters();
case EXCLUDE: case EXCLUDE:
return this.annotation.excludeFilters(); return this.annotation.excludeFilters();
default: default:
throw new IllegalStateException("Unsupported type " + type); throw new IllegalStateException("Unsupported type " + type);
} }
} }
......
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Sample test for {@link DataMongoTest @DataMongoTest} * Sample test for {@link DataMongoTest @DataMongoTest}
* *
* @author Michael J. Simons * @author Michael Simons
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@DataMongoTest @DataMongoTest
...@@ -54,10 +54,8 @@ public class DataMongoTestIntegrationTests { ...@@ -54,10 +54,8 @@ public class DataMongoTestIntegrationTests {
public void testRepository() { public void testRepository() {
ExampleDocument exampleDocument = new ExampleDocument(); ExampleDocument exampleDocument = new ExampleDocument();
exampleDocument.setText("Look, new @DataMongoTest!"); exampleDocument.setText("Look, new @DataMongoTest!");
exampleDocument = this.exampleRepository.save(exampleDocument); exampleDocument = this.exampleRepository.save(exampleDocument);
assertThat(exampleDocument.getId()).isNotNull(); assertThat(exampleDocument.getId()).isNotNull();
assertThat(this.mongoTemplate.collectionExists("exampleDocuments")).isTrue(); assertThat(this.mongoTemplate.collectionExists("exampleDocuments")).isTrue();
} }
......
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -29,7 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -29,7 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Integration test with custom include filter for {@link DataMongoTest}. * Integration test with custom include filter for {@link DataMongoTest}.
* *
* @author Michael J. Simons * @author Michael Simons
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@DataMongoTest(includeFilters = @Filter(Service.class)) @DataMongoTest(includeFilters = @Filter(Service.class))
......
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -21,7 +21,7 @@ import org.springframework.data.mongodb.core.mapping.Document; ...@@ -21,7 +21,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
/** /**
* Example document used with {@link DataMongoTest} tests. * Example document used with {@link DataMongoTest} tests.
* *
* @author Michael J. Simons * @author Michael Simons
*/ */
@Document(collection = "exampleDocuments") @Document(collection = "exampleDocuments")
public class ExampleDocument { public class ExampleDocument {
......
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -21,7 +21,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; ...@@ -21,7 +21,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
/** /**
* Example {@link SpringBootApplication} used with {@link DataMongoTest} tests. * Example {@link SpringBootApplication} used with {@link DataMongoTest} tests.
* *
* @author Michael J. Simons * @author Michael Simons
*/ */
@SpringBootApplication @SpringBootApplication
public class ExampleMongoApplication { public class ExampleMongoApplication {
......
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -21,7 +21,8 @@ import org.springframework.data.mongodb.repository.MongoRepository; ...@@ -21,7 +21,8 @@ import org.springframework.data.mongodb.repository.MongoRepository;
/** /**
* Example repository used with {@link DataMongoTest} tests. * Example repository used with {@link DataMongoTest} tests.
* *
* @author Michael J. Simons * @author Michael Simons
*/ */
public interface ExampleRepository extends MongoRepository<ExampleDocument, String> { public interface ExampleRepository extends MongoRepository<ExampleDocument, String> {
} }
...@@ -22,10 +22,11 @@ import org.springframework.stereotype.Service; ...@@ -22,10 +22,11 @@ import org.springframework.stereotype.Service;
/** /**
* Example service used with {@link DataMongoTest} tests. * Example service used with {@link DataMongoTest} tests.
* *
* @author Michael J. Simons * @author Michael Simons
*/ */
@Service @Service
public class ExampleService { public class ExampleService {
private final MongoTemplate mongoTemplate; private final MongoTemplate mongoTemplate;
public ExampleService(MongoTemplate mongoTemplate) { public ExampleService(MongoTemplate mongoTemplate) {
......
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
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