Skip to content

Commit 5e7a8b2

Browse files
committed
Polishing
1 parent ea3250c commit 5e7a8b2

File tree

3 files changed

+38
-38
lines changed

3 files changed

+38
-38
lines changed

spring-web/src/test/java/org/springframework/web/method/ResolvableMethod.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.springframework.core.annotation.AnnotatedElementUtils;
4848
import org.springframework.core.annotation.AnnotationUtils;
4949
import org.springframework.core.annotation.SynthesizingMethodParameter;
50+
import org.springframework.lang.Nullable;
5051
import org.springframework.objenesis.ObjenesisException;
5152
import org.springframework.objenesis.SpringObjenesis;
5253
import org.springframework.util.Assert;
@@ -120,6 +121,7 @@
120121
* </pre>
121122
*
122123
* @author Rossen Stoyanchev
124+
* @since 5.0
123125
*/
124126
public class ResolvableMethod {
125127

@@ -133,7 +135,7 @@ public class ResolvableMethod {
133135

134136

135137
private ResolvableMethod(Method method) {
136-
Assert.notNull(method, "method is required");
138+
Assert.notNull(method, "Method is required");
137139
this.method = method;
138140
}
139141

@@ -202,14 +204,14 @@ public final ArgResolver annotNotPresent(Class<? extends Annotation>... annotati
202204
return new ArgResolver().annotNotPresent(annotationTypes);
203205
}
204206

205-
206207
@Override
207208
public String toString() {
208209
return "ResolvableMethod=" + formatMethod();
209210
}
210211

212+
211213
private String formatMethod() {
212-
return (this.method().getName() +
214+
return (method().getName() +
213215
Arrays.stream(this.method.getParameters())
214216
.map(this::formatParameter)
215217
.collect(joining(",\n\t", "(\n\t", "\n)")));
@@ -262,13 +264,11 @@ public static class Builder<T> {
262264

263265
private final List<Predicate<Method>> filters = new ArrayList<>(4);
264266

265-
266267
private Builder(Class<?> objectClass) {
267268
Assert.notNull(objectClass, "Class must not be null");
268269
this.objectClass = objectClass;
269270
}
270271

271-
272272
private void addFilter(String message, Predicate<Method> filter) {
273273
this.filters.add(new LabeledPredicate<>(message, filter));
274274
}
@@ -394,7 +394,6 @@ public ResolvableMethod mockCall(Consumer<T> invoker) {
394394
return new ResolvableMethod(method);
395395
}
396396

397-
398397
// Build & resolve shortcuts...
399398

400399
/**
@@ -448,7 +447,6 @@ public MethodParameter resolveReturnType(ResolvableType returnType) {
448447
return returning(returnType).build().returnType();
449448
}
450449

451-
452450
@Override
453451
public String toString() {
454452
return "ResolvableMethod.Builder[\n" +
@@ -462,6 +460,7 @@ private String formatFilters() {
462460
}
463461
}
464462

463+
465464
/**
466465
* Predicate with a descriptive label.
467466
*/
@@ -471,7 +470,6 @@ private static class LabeledPredicate<T> implements Predicate<T> {
471470

472471
private final Predicate<T> delegate;
473472

474-
475473
private LabeledPredicate(String label, Predicate<T> delegate) {
476474
this.label = label;
477475
this.delegate = delegate;
@@ -504,14 +502,14 @@ public String toString() {
504502
}
505503
}
506504

505+
507506
/**
508507
* Resolver for method arguments.
509508
*/
510509
public class ArgResolver {
511510

512511
private final List<Predicate<MethodParameter>> filters = new ArrayList<>(4);
513512

514-
515513
@SafeVarargs
516514
private ArgResolver(Predicate<MethodParameter>... filter) {
517515
this.filters.addAll(Arrays.asList(filter));
@@ -603,17 +601,18 @@ private List<MethodParameter> applyFilters() {
603601
}
604602
}
605603

604+
606605
private static class MethodInvocationInterceptor
607606
implements org.springframework.cglib.proxy.MethodInterceptor, MethodInterceptor {
608607

609608
private Method invokedMethod;
610609

611-
612610
Method getInvokedMethod() {
613611
return this.invokedMethod;
614612
}
615613

616614
@Override
615+
@Nullable
617616
public Object intercept(Object object, Method method, Object[] args, MethodProxy proxy) {
618617
if (ReflectionUtils.isObjectMethod(method)) {
619618
return ReflectionUtils.invokeMethod(method, object, args);
@@ -625,6 +624,7 @@ public Object intercept(Object object, Method method, Object[] args, MethodProxy
625624
}
626625

627626
@Override
627+
@Nullable
628628
public Object invoke(org.aopalliance.intercept.MethodInvocation inv) throws Throwable {
629629
return intercept(inv.getThis(), inv.getMethod(), inv.getArguments(), null);
630630
}

src/docs/asciidoc/core/core-aop.adoc

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3054,41 +3054,41 @@ container and once through the aspect.
30543054
[[aop-configurable-testing]]
30553055
==== Unit Testing `@Configurable` Objects
30563056

3057-
One of the goals of the `@Configurable` support is to enable independent unit testing of
3058-
domain objects without the difficulties associated with hard-coded lookups. If
3059-
`@Configurable` types have not been woven by AspectJ, the annotation has no affect
3060-
during unit testing. You can set mock or stub property references in the
3061-
object under test and proceed as normal. If `@Configurable` types have been woven by
3062-
AspectJ, you can still unit test outside of the container as normal, but you
3063-
see a warning message each time that you construct an `@Configurable` object indicating
3064-
that it has not been configured by Spring.
3057+
One of the goals of the `@Configurable` support is to enable independent unit testing
3058+
of domain objects without the difficulties associated with hard-coded lookups.
3059+
If `@Configurable` types have not been woven by AspectJ, the annotation has no affect
3060+
during unit testing. You can set mock or stub property references in the object under
3061+
test and proceed as normal. If `@Configurable` types have been woven by AspectJ,
3062+
you can still unit test outside of the container as normal, but you see a warning
3063+
message each time that you construct a `@Configurable` object indicating that it has
3064+
not been configured by Spring.
30653065

30663066

30673067
[[aop-configurable-container]]
30683068
==== Working with Multiple Application Contexts
30693069

3070-
The `AnnotationBeanConfigurerAspect` that is used to implement the `@Configurable` support is an
3071-
AspectJ singleton aspect. The scope of a singleton aspect is the same as the scope of
3072-
`static` members: There is one aspect instance per classloader that
3073-
defines the type. This means that, if you define multiple application contexts within the
3074-
same classloader hierarchy, you need to consider where to define the
3075-
`@EnableSpringConfigured` bean and where to place `spring-aspects.jar` on the classpath.
3076-
3077-
Consider a typical Spring web application configuration that has a shared parent application context
3078-
that defines common business services, everything needed to support those services, and one child
3079-
application context for each servlet (which contains definitions particular to that servlet). All
3080-
of these contexts co-exist within the same classloader hierarchy, and so the
3081-
`AnnotationBeanConfigurerAspect` can hold a reference to only one of them. In this case,
3082-
we recommend defining the `@EnableSpringConfigured` bean in the shared (parent)
3083-
application context. This defines the services that you are likely to want to inject
3084-
into domain objects. A consequence is that you cannot configure domain objects with
3085-
references to beans defined in the child (servlet-specific) contexts by using the
3070+
The `AnnotationBeanConfigurerAspect` that is used to implement the `@Configurable` support
3071+
is an AspectJ singleton aspect. The scope of a singleton aspect is the same as the scope
3072+
of `static` members: There is one aspect instance per classloader that defines the type.
3073+
This means that, if you define multiple application contexts within the same classloader
3074+
hierarchy, you need to consider where to define the `@EnableSpringConfigured` bean and
3075+
where to place `spring-aspects.jar` on the classpath.
3076+
3077+
Consider a typical Spring web application configuration that has a shared parent application
3078+
context that defines common business services, everything needed to support those services,
3079+
and one child application context for each servlet (which contains definitions particular
3080+
to that servlet). All of these contexts co-exist within the same classloader hierarchy,
3081+
and so the `AnnotationBeanConfigurerAspect` can hold a reference to only one of them.
3082+
In this case, we recommend defining the `@EnableSpringConfigured` bean in the shared
3083+
(parent) application context. This defines the services that you are likely to want to
3084+
inject into domain objects. A consequence is that you cannot configure domain objects
3085+
with references to beans defined in the child (servlet-specific) contexts by using the
30863086
@Configurable mechanism (which is probably not something you want to do anyway).
30873087

30883088
When deploying multiple web applications within the same container, ensure that each
3089-
web application loads the types in `spring-aspects.jar` by using its own classloader (for
3090-
example, by placing `spring-aspects.jar` in `'WEB-INF/lib'`). If `spring-aspects.jar` is
3091-
added only to the container-wide classpath (and hence loaded by the shared parent
3089+
web application loads the types in `spring-aspects.jar` by using its own classloader
3090+
(for example, by placing `spring-aspects.jar` in `'WEB-INF/lib'`). If `spring-aspects.jar`
3091+
is added only to the container-wide classpath (and hence loaded by the shared parent
30923092
classloader), all web applications share the same aspect instance (which is probably
30933093
not what you want).
30943094

src/docs/asciidoc/web/webmvc.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3266,7 +3266,7 @@ response body through message conversion (versus view resolution or template ren
32663266

32673267
On startup, the infrastructure classes for `@RequestMapping` and `@ExceptionHandler` methods
32683268
detect Spring beans of type `@ControllerAdvice` and then apply their methods at runtime.
3269-
Global `@ExceptionHandler` methods (from an `@ControllerAdvice`) are applied _after_ local
3269+
Global `@ExceptionHandler` methods (from a `@ControllerAdvice`) are applied _after_ local
32703270
ones (from the `@Controller`). By contrast, global `@ModelAttribute` and `@InitBinder`
32713271
methods are applied _before_ local ones.
32723272

0 commit comments

Comments
 (0)