Refer to static nested classes, not static inner classes
Various parts of the reference manual as well as the Javadoc for AnnotationConfigContextLoaderUtils improperly refer to "static inner classes" even though this terminology does not exist in Java. The Java Language Specification explicitly refers to such classes as "static nested classes." An "inner class" must be non-static by definition.
This commit is contained in:
parent
e97712b95b
commit
c5c32ec206
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -41,7 +41,7 @@ public abstract class AnnotationConfigContextLoaderUtils {
|
|||
|
||||
/**
|
||||
* Detect the default configuration classes for the supplied test class.
|
||||
* <p>The returned class array will contain all static inner classes of
|
||||
* <p>The returned class array will contain all static nested classes of
|
||||
* the supplied class that meet the requirements for {@code @Configuration}
|
||||
* class implementations as specified in the documentation for
|
||||
* {@link Configuration @Configuration}.
|
||||
|
|
@ -78,7 +78,7 @@ public abstract class AnnotationConfigContextLoaderUtils {
|
|||
if (configClasses.isEmpty()) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info(String.format("Could not detect default configuration classes for test class [%s]: " +
|
||||
"%s does not declare any static, non-private, non-final, inner classes " +
|
||||
"%s does not declare any static, non-private, non-final, nested classes " +
|
||||
"annotated with @Configuration.", declaringClass.getName(), declaringClass.getSimpleName()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1791,15 +1791,15 @@ You use the `Class` property in one of two ways:
|
|||
****
|
||||
.Inner class names
|
||||
If you want to configure a bean definition for a `static` nested class, you have to use
|
||||
the __binary__ name of the inner class.
|
||||
the __binary__ name of the nested class.
|
||||
|
||||
For example, if you have a class called `Foo` in the `com.example` package, and this
|
||||
`Foo` class has a `static` inner class called `Bar`, the value of the `'class'`
|
||||
`Foo` class has a `static` nested class called `Bar`, the value of the `'class'`
|
||||
attribute on a bean definition would be...
|
||||
|
||||
`com.example.Foo$Bar`
|
||||
|
||||
Notice the use of the `$` character in the name to separate the inner class name from
|
||||
Notice the use of the `$` character in the name to separate the nested class name from
|
||||
the outer class name.
|
||||
****
|
||||
|
||||
|
|
@ -20060,20 +20060,20 @@ the discussion of __`@Bean` Lite Mode__.
|
|||
If you omit the `classes` attribute from the `@ContextConfiguration` annotation, the
|
||||
TestContext framework will attempt to detect the presence of default configuration
|
||||
classes. Specifically, `AnnotationConfigContextLoader` and
|
||||
`AnnotationConfigWebContextLoader` will detect all static inner classes of the test class
|
||||
`AnnotationConfigWebContextLoader` will detect all `static` nested classes of the test class
|
||||
that meet the requirements for configuration class implementations as specified in the
|
||||
`@Configuration` javadocs. In the following example, the `OrderServiceTest` class
|
||||
declares a static inner configuration class named `Config` that will be automatically
|
||||
declares a `static` nested configuration class named `Config` that will be automatically
|
||||
used to load the `ApplicationContext` for the test class. Note that the name of the
|
||||
configuration class is arbitrary. In addition, a test class can contain more than one
|
||||
static inner configuration class if desired.
|
||||
`static` nested configuration class if desired.
|
||||
|
||||
[source,java,indent=0]
|
||||
[subs="verbatim,quotes"]
|
||||
----
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
// ApplicationContext will be loaded from the
|
||||
// static inner Config class
|
||||
// static nested Config class
|
||||
**@ContextConfiguration**
|
||||
public class OrderServiceTest {
|
||||
|
||||
|
|
@ -25092,7 +25092,7 @@ Querying and populating a number of domain objects:
|
|||
|
||||
If the last two snippets of code actually existed in the same application, it would make
|
||||
sense to remove the duplication present in the two `RowMapper` anonymous inner classes,
|
||||
and extract them out into a single class (typically a `static` inner class) that can
|
||||
and extract them out into a single class (typically a `static` nested class) that can
|
||||
then be referenced by DAO methods as needed. For example, it may be better to write the
|
||||
last code snippet as follows:
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue