Skip to content

Commit b43e733

Browse files
committed
Polishing
1 parent 6711515 commit b43e733

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/annotation/AnnotationBeanWiringInfoResolver.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -44,24 +44,23 @@ public BeanWiringInfo resolveWiringInfo(Object beanInstance) {
4444
}
4545

4646
/**
47-
* Build the BeanWiringInfo for the given Configurable annotation.
47+
* Build the {@link BeanWiringInfo} for the given {@link Configurable} annotation.
4848
* @param beanInstance the bean instance
4949
* @param annotation the Configurable annotation found on the bean class
5050
* @return the resolved BeanWiringInfo
5151
*/
5252
protected BeanWiringInfo buildWiringInfo(Object beanInstance, Configurable annotation) {
5353
if (!Autowire.NO.equals(annotation.autowire())) {
54+
// Autowiring by name or by type
5455
return new BeanWiringInfo(annotation.autowire().value(), annotation.dependencyCheck());
5556
}
57+
else if (!"".equals(annotation.value())) {
58+
// Explicitly specified bean name for bean definition to take property values from
59+
return new BeanWiringInfo(annotation.value(), false);
60+
}
5661
else {
57-
if (!"".equals(annotation.value())) {
58-
// explicitly specified bean name
59-
return new BeanWiringInfo(annotation.value(), false);
60-
}
61-
else {
62-
// default bean name
63-
return new BeanWiringInfo(getDefaultBeanName(beanInstance), true);
64-
}
62+
// Default bean name for bean definition to take property values from
63+
return new BeanWiringInfo(getDefaultBeanName(beanInstance), true);
6564
}
6665
}
6766

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
/**
3636
* A filter that wraps the {@link HttpServletResponse} and overrides its
3737
* {@link HttpServletResponse#encodeURL(String) encodeURL} method in order to
38-
* translate internal resource request URLs into public URL paths for external
39-
* use.
38+
* translate internal resource request URLs into public URL paths for external use.
4039
*
4140
* @author Jeremy Grelle
4241
* @author Rossen Stoyanchev
@@ -51,7 +50,8 @@ public class ResourceUrlEncodingFilter extends GenericFilterBean {
5150

5251
@Override
5352
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
54-
throws IOException, ServletException {
53+
throws ServletException, IOException {
54+
5555
if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse)) {
5656
throw new ServletException("ResourceUrlEncodingFilter only supports HTTP requests");
5757
}
@@ -62,11 +62,11 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
6262
filterChain.doFilter(wrappedRequest, wrappedResponse);
6363
}
6464

65+
6566
private static class ResourceUrlEncodingRequestWrapper extends HttpServletRequestWrapper {
6667

6768
private ResourceUrlProvider resourceUrlProvider;
6869

69-
/* Cache the index and prefix of the path within the DispatcherServlet mapping */
7070
private Integer indexLookupPath;
7171

7272
private String prefixLookupPath;
@@ -76,11 +76,11 @@ private static class ResourceUrlEncodingRequestWrapper extends HttpServletReques
7676
}
7777

7878
@Override
79-
public void setAttribute(String name, Object o) {
80-
super.setAttribute(name, o);
79+
public void setAttribute(String name, Object value) {
80+
super.setAttribute(name, value);
8181
if (ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR.equals(name)) {
82-
if(o instanceof ResourceUrlProvider) {
83-
initLookupPath((ResourceUrlProvider) o);
82+
if (value instanceof ResourceUrlProvider) {
83+
initLookupPath((ResourceUrlProvider) value);
8484
}
8585
}
8686

@@ -94,7 +94,6 @@ private void initLookupPath(ResourceUrlProvider urlProvider) {
9494
String lookupPath = pathHelper.getLookupPathForRequest(this);
9595
this.indexLookupPath = requestUri.lastIndexOf(lookupPath);
9696
this.prefixLookupPath = requestUri.substring(0, this.indexLookupPath);
97-
9897
if ("/".equals(lookupPath) && !"/".equals(requestUri)) {
9998
String contextPath = pathHelper.getContextPath(this);
10099
if (requestUri.equals(contextPath)) {
@@ -107,10 +106,11 @@ private void initLookupPath(ResourceUrlProvider urlProvider) {
107106

108107
public String resolveUrlPath(String url) {
109108
if (this.resourceUrlProvider == null) {
110-
logger.debug("Request attribute exposing ResourceUrlProvider not found");
109+
logger.trace("ResourceUrlProvider not available via request attribute " +
110+
"ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR");
111111
return null;
112112
}
113-
if (url.startsWith(this.prefixLookupPath)) {
113+
if (this.indexLookupPath != null && url.startsWith(this.prefixLookupPath)) {
114114
int suffixIndex = getQueryParamsIndex(url);
115115
String suffix = url.substring(suffixIndex);
116116
String lookupPath = url.substring(this.indexLookupPath, suffixIndex);
@@ -148,4 +148,4 @@ public String encodeURL(String url) {
148148
}
149149
}
150150

151-
}
151+
}

0 commit comments

Comments
 (0)