Skip to content

Commit c678c1f

Browse files
committed
Polish
1 parent 034ce0a commit c678c1f

23 files changed

+54
-86
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/RequestMappingEndpoint.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,23 @@ protected void extractHandlerMappings(ApplicationContext applicationContext,
110110
.getBeansOfType(AbstractUrlHandlerMapping.class);
111111
for (String name : mappings.keySet()) {
112112
AbstractUrlHandlerMapping mapping = mappings.get(name);
113-
if (AopUtils.isCglibProxy(mapping)) {
114-
// The getHandlerMap() method is final so it cannot be cglibbed
115-
continue;
116-
}
117-
Map<String, Object> handlers = mapping.getHandlerMap();
113+
Map<String, Object> handlers = getHandlerMap(mapping);
118114
for (String key : handlers.keySet()) {
119115
result.put(key, Collections.singletonMap("bean", name));
120116
}
121117
}
122118
}
123119
}
124120

121+
private Map<String, Object> getHandlerMap(AbstractUrlHandlerMapping mapping) {
122+
if (AopUtils.isCglibProxy(mapping)) {
123+
// If the AbstractUrlHandlerMapping is a cglib proxy we can't call
124+
// the final getHandlerMap() method.
125+
return Collections.emptyMap();
126+
}
127+
return mapping.getHandlerMap();
128+
}
129+
125130
protected void extractHandlerMappings(
126131
Collection<AbstractUrlHandlerMapping> handlerMappings,
127132
Map<String, Object> result) {

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/RequestMappingEndpointTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import static org.junit.Assert.assertTrue;
3939

4040
/**
41+
* Tests for {@link RequestMappingEndpoint}.
42+
*
4143
* @author Dave Syer
4244
*/
4345
public class RequestMappingEndpointTests {

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/MvcEndpointsTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@
2323
import static org.junit.Assert.assertEquals;
2424

2525
/**
26+
* Tests for {@link MvcEndpoints}.
27+
*
2628
* @author Dave Syer
2729
*/
2830
public class MvcEndpointsTests {
2931

3032
private MvcEndpoints endpoints = new MvcEndpoints();
33+
3134
private StaticApplicationContext context = new StaticApplicationContext();
3235

3336
@Test

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerProperties.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,10 @@ public class FreeMarkerProperties extends AbstractTemplateViewResolverProperties
4848
*/
4949
private String[] templateLoaderPath = new String[] { DEFAULT_TEMPLATE_LOADER_PATH };
5050

51-
/**
52-
* Switches off MVC view resolution if set to false (default true).
53-
*/
54-
private boolean enabled = true;
55-
5651
public FreeMarkerProperties() {
5752
super(DEFAULT_PREFIX, DEFAULT_SUFFIX);
5853
}
5954

60-
public boolean isEnabled() {
61-
return this.enabled;
62-
}
63-
64-
public void setEnabled(boolean enabled) {
65-
this.enabled = enabled;
66-
}
67-
6855
public Map<String, String> getSettings() {
6956
return this.settings;
7057
}

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateProperties.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,6 @@ public class GroovyTemplateProperties extends AbstractViewResolverProperties {
5050
*/
5151
private Map<String, Object> configuration = new HashMap<String, Object>();
5252

53-
/**
54-
* Switches off MVC view resolution if set to false (default true).
55-
*/
56-
private boolean enabled = true;
57-
58-
public boolean isEnabled() {
59-
return this.enabled;
60-
}
61-
62-
public void setEnabled(boolean enabled) {
63-
this.enabled = enabled;
64-
}
65-
6653
public String getPrefix() {
6754
return this.prefix;
6855
}

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/template/AbstractViewResolverProperties.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
*/
3030
public abstract class AbstractViewResolverProperties {
3131

32+
/**
33+
* Enable MVC view resolution for this technology.
34+
*/
35+
private boolean enabled = true;
36+
3237
/**
3338
* Enable template caching.
3439
*/
@@ -54,6 +59,14 @@ public abstract class AbstractViewResolverProperties {
5459
*/
5560
private boolean checkTemplateLocation = true;
5661

62+
public void setEnabled(boolean enabled) {
63+
this.enabled = enabled;
64+
}
65+
66+
public boolean isEnabled() {
67+
return this.enabled;
68+
}
69+
5770
public void setCheckTemplateLocation(boolean checkTemplateLocation) {
5871
this.checkTemplateLocation = checkTemplateLocation;
5972
}

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public class ThymeleafProperties {
7777
private String[] excludedViewNames;
7878

7979
/**
80-
* Switches off MVC view resolution if set to false (default true).
80+
* Enable MVC Thymeleaf view resolution.
8181
*/
8282
private boolean enabled = true;
8383

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/velocity/VelocityProperties.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,10 @@ public class VelocityProperties extends AbstractTemplateViewResolverProperties {
7171
*/
7272
private boolean preferFileSystemAccess = true;
7373

74-
/**
75-
* Switches off MVC view resolution if set to false (default true).
76-
*/
77-
private boolean enabled = true;
78-
7974
public VelocityProperties() {
8075
super(DEFAULT_PREFIX, DEFAULT_SUFFIX);
8176
}
8277

83-
public boolean isEnabled() {
84-
return this.enabled;
85-
}
86-
87-
public void setEnabled(boolean enabled) {
88-
this.enabled = enabled;
89-
}
90-
9178
public String getDateToolAttribute() {
9279
return this.dateToolAttribute;
9380
}

spring-boot/src/main/java/org/springframework/boot/bind/PropertiesConfigurationFactory.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ public void bindPropertiesToTarget() throws BindException {
234234
}
235235

236236
private void doBindPropertiesToTarget() throws BindException {
237-
238237
RelaxedDataBinder dataBinder = (this.targetName != null ? new RelaxedDataBinder(
239238
this.target, this.targetName) : new RelaxedDataBinder(this.target));
240239
if (this.validator != null) {
@@ -247,7 +246,15 @@ private void doBindPropertiesToTarget() throws BindException {
247246
dataBinder.setIgnoreInvalidFields(this.ignoreInvalidFields);
248247
dataBinder.setIgnoreUnknownFields(this.ignoreUnknownFields);
249248
customizeBinder(dataBinder);
249+
Set<String> names = getNames();
250+
PropertyValues propertyValues = getPropertyValues(names);
251+
dataBinder.bind(propertyValues);
252+
if (this.validator != null) {
253+
validate(dataBinder);
254+
}
255+
}
250256

257+
private Set<String> getNames() {
251258
Set<String> names = new HashSet<String>();
252259
if (this.target != null) {
253260
PropertyDescriptor[] descriptors = BeanUtils
@@ -262,17 +269,15 @@ private void doBindPropertiesToTarget() throws BindException {
262269
}
263270
}
264271
}
265-
PropertyNamePatternsMatcher patterns = new DefaultPropertyNamePatternsMatcher(
266-
names);
267-
268-
PropertyValues propertyValues = (this.properties != null ? new MutablePropertyValues(
269-
this.properties) : new PropertySourcesPropertyValues(
270-
this.propertySources, patterns, names));
271-
dataBinder.bind(propertyValues);
272+
return names;
273+
}
272274

273-
if (this.validator != null) {
274-
validate(dataBinder);
275+
private PropertyValues getPropertyValues(Set<String> names) {
276+
if (this.properties != null) {
277+
return new MutablePropertyValues(this.properties);
275278
}
279+
return new PropertySourcesPropertyValues(this.propertySources,
280+
new DefaultPropertyNamePatternsMatcher(names), names);
276281
}
277282

278283
private void validate(RelaxedDataBinder dataBinder) throws BindException {

spring-boot/src/main/java/org/springframework/boot/bind/SimplePropertyNamePatternsMatcher.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ public SimplePropertyNamePatternsMatcher(Collection<String> patterns) {
4040
public boolean matches(String propertyName) {
4141
return PatternMatchUtils.simpleMatch(this.patterns, propertyName);
4242
}
43+
4344
}

0 commit comments

Comments
 (0)