Skip to content

Commit eb30fe0

Browse files
committed
Merge branch '1.5.x'
2 parents de7b7ac + 5d69318 commit eb30fe0

File tree

3 files changed

+58
-19
lines changed

3 files changed

+58
-19
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfiguration.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,22 @@
4141
* {@link TomcatServletWebServerFactory} (unless you have defined your own
4242
* {@link ServletWebServerFactory} bean).
4343
* <p>
44+
* When using {@link SpringBootApplication}, the auto-configuration of the context is
45+
* automatically enabled and adding this annotation has therefore no additional effect.
46+
* <p>
4447
* Auto-configuration tries to be as intelligent as possible and will back-away as you
4548
* define more of your own configuration. You can always manually {@link #exclude()} any
4649
* configuration that you never want to apply (use {@link #excludeName()} if you don't
4750
* have access to them). You can also exclude them via the
4851
* {@code spring.autoconfigure.exclude} property. Auto-configuration is always applied
4952
* after user-defined beans have been registered.
5053
* <p>
51-
* The package of the class that is annotated with {@code @EnableAutoConfiguration} has
52-
* specific significance and is often used as a 'default'. For example, it will be used
53-
* when scanning for {@code @Entity} classes. It is generally recommended that you place
54-
* {@code @EnableAutoConfiguration} in a root package so that all sub-packages and classes
55-
* can be searched.
54+
* The package of the class that is annotated with {@code @EnableAutoConfiguration},
55+
* usually via {@code @SpringBootApplication}, has specific significance and is often used
56+
* as a 'default'. For example, it will be used when scanning for {@code @Entity} classes.
57+
* It is generally recommended that you place {@code @EnableAutoConfiguration} (if you're
58+
* not using {@code @SpringBootApplication}) in a root package so that all sub-packages
59+
* and classes can be searched.
5660
* <p>
5761
* Auto-configuration classes are regular Spring {@link Configuration} beans. They are
5862
* located using the {@link SpringFactoriesLoader} mechanism (keyed against this class).
@@ -66,6 +70,7 @@
6670
* @see ConditionalOnMissingBean
6771
* @see ConditionalOnClass
6872
* @see AutoConfigureAfter
73+
* @see SpringBootApplication
6974
*/
7075
@Target(ElementType.TYPE)
7176
@Retention(RetentionPolicy.RUNTIME)

spring-boot/src/main/java/org/springframework/boot/jackson/JsonComponentModule.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.jackson;
1818

19+
import java.lang.reflect.Modifier;
1920
import java.util.Map;
2021

2122
import javax.annotation.PostConstruct;
@@ -78,8 +79,9 @@ private void addJsonBean(Object bean) {
7879
addDeserializerWithDeducedType((JsonDeserializer<?>) bean);
7980
}
8081
for (Class<?> innerClass : bean.getClass().getDeclaredClasses()) {
81-
if (JsonSerializer.class.isAssignableFrom(innerClass)
82-
|| JsonDeserializer.class.isAssignableFrom(innerClass)) {
82+
if (!Modifier.isAbstract(innerClass.getModifiers()) &&
83+
(JsonSerializer.class.isAssignableFrom(innerClass)
84+
|| JsonDeserializer.class.isAssignableFrom(innerClass))) {
8385
try {
8486
addJsonBean(innerClass.newInstance());
8587
}

spring-boot/src/test/java/org/springframework/boot/jackson/JsonComponentModuleTests.java

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818

1919
import com.fasterxml.jackson.databind.Module;
2020
import com.fasterxml.jackson.databind.ObjectMapper;
21+
import org.junit.After;
2122
import org.junit.Test;
2223

2324
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -31,34 +32,54 @@
3132
*/
3233
public class JsonComponentModuleTests {
3334

35+
private AnnotationConfigApplicationContext context;
36+
37+
@After
38+
public void closeContext() {
39+
if (this.context != null) {
40+
this.context.close();
41+
}
42+
}
43+
3444
@Test
3545
public void moduleShouldRegisterSerializers() throws Exception {
36-
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
37-
JsonComponentModule.class, OnlySerializer.class);
38-
JsonComponentModule module = context.getBean(JsonComponentModule.class);
46+
load(OnlySerializer.class);
47+
JsonComponentModule module = this.context.getBean(JsonComponentModule.class);
3948
assertSerialize(module);
40-
context.close();
4149
}
4250

4351
@Test
4452
public void moduleShouldRegisterDeserializers() throws Exception {
45-
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
46-
JsonComponentModule.class, OnlyDeserializer.class);
47-
JsonComponentModule module = context.getBean(JsonComponentModule.class);
53+
load(OnlyDeserializer.class);
54+
JsonComponentModule module = this.context.getBean(JsonComponentModule.class);
4855
assertDeserialize(module);
49-
context.close();
5056
}
5157

5258
@Test
5359
public void moduleShouldRegisterInnerClasses() throws Exception {
60+
load(NameAndAgeJsonComponent.class);
61+
JsonComponentModule module = this.context.getBean(JsonComponentModule.class);
62+
assertSerialize(module);
63+
assertDeserialize(module);
64+
}
65+
66+
@Test
67+
public void moduleShouldAllowInnerAbstractClasses() throws Exception {
5468
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
55-
JsonComponentModule.class, NameAndAgeJsonComponent.class);
69+
JsonComponentModule.class, ComponentWithInnerAbstractClass.class);
5670
JsonComponentModule module = context.getBean(JsonComponentModule.class);
5771
assertSerialize(module);
58-
assertDeserialize(module);
5972
context.close();
6073
}
6174

75+
private void load(Class<?>... configs) {
76+
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
77+
ctx.register(configs);
78+
ctx.register(JsonComponentModule.class);
79+
ctx.refresh();
80+
this.context = ctx;
81+
}
82+
6283
private void assertSerialize(Module module) throws Exception {
6384
ObjectMapper mapper = new ObjectMapper();
6485
mapper.registerModule(module);
@@ -85,4 +106,15 @@ static class OnlyDeserializer extends NameAndAgeJsonComponent.Deserializer {
85106

86107
}
87108

109+
@JsonComponent
110+
static class ComponentWithInnerAbstractClass {
111+
112+
private static abstract class AbstractSerializer extends NameAndAgeJsonComponent.Serializer {
113+
114+
}
115+
116+
static class ConcreteSerializer extends AbstractSerializer {
117+
118+
}
119+
}
88120
}

0 commit comments

Comments
 (0)