@ -481,33 +481,38 @@ pointcut expressions by name. The following example shows three pointcut express
@@ -481,33 +481,38 @@ pointcut expressions by name. The following example shows three pointcut express
@ -860,14 +860,10 @@ we can parse our custom XML content, as you can see in the following example:
@@ -860,14 +860,10 @@ we can parse our custom XML content, as you can see in the following example:
import java.text.SimpleDateFormat;
// We use the Spring-provided AbstractSingleBeanDefinitionParser to handle a lot of
// the basic grunt work of creating a single BeanDefinition.
public class SimpleDateFormatBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
public class SimpleDateFormatBeanDefinitionParser extends AbstractSingleBeanDefinitionParser { // <1>
protected Class getBeanClass(Element element) {
// We supply the AbstractSingleBeanDefinitionParser superclass with the type that our
@ -884,6 +880,11 @@ we can parse our custom XML content, as you can see in the following example:
@@ -884,6 +880,11 @@ we can parse our custom XML content, as you can see in the following example:
}
----
<1> We use the Spring-provided `AbstractSingleBeanDefinitionParser` to handle a lot of
the basic grunt work of creating a single `BeanDefinition`.
<2> We supply the `AbstractSingleBeanDefinitionParser` superclass with the type that our
@ -896,13 +897,9 @@ we can parse our custom XML content, as you can see in the following example:
@@ -896,13 +897,9 @@ we can parse our custom XML content, as you can see in the following example:
import java.text.SimpleDateFormat
// We use the Spring-provided AbstractSingleBeanDefinitionParser to handle a lot of
// the basic grunt work of creating a single BeanDefinition.
class SimpleDateFormatBeanDefinitionParser : AbstractSingleBeanDefinitionParser() {
class SimpleDateFormatBeanDefinitionParser : AbstractSingleBeanDefinitionParser() { // <1>
override fun getBeanClass(element: Element): Class<*>? {
// We supply the AbstractSingleBeanDefinitionParser superclass with the type that our
// single BeanDefinition represents.
override fun getBeanClass(element: Element): Class<*>? { // <2>
return SimpleDateFormat::class.java
}
@ -919,6 +916,11 @@ we can parse our custom XML content, as you can see in the following example:
@@ -919,6 +916,11 @@ we can parse our custom XML content, as you can see in the following example:
}
}
----
<1> We use the Spring-provided `AbstractSingleBeanDefinitionParser` to handle a lot of
the basic grunt work of creating a single `BeanDefinition`.
<2> We supply the `AbstractSingleBeanDefinitionParser` superclass with the type that our
single `BeanDefinition` represents.
In this simple case, this is all that we need to do. The creation of our single
`BeanDefinition` is handled by the `AbstractSingleBeanDefinitionParser` superclass, as
@Resource(name="myMovieFinder") // This line injects a @Resource
@Resource(name="myMovieFinder") // <1>
private lateinit var movieFinder:MovieFinder
}
----
<1> This line injects a `@Resource`.
If no name is explicitly specified, the default name is derived from the field name or
@ -5986,10 +5992,8 @@ named "customerPreferenceDao" and then falls back to a primary type match for th
@@ -5986,10 +5992,8 @@ named "customerPreferenceDao" and then falls back to a primary type match for th
// The context field is injected based on the known resolvable dependency
// type: ApplicationContext
@Resource
private ApplicationContext context;
private ApplicationContext context; // <1>
public MovieRecommender() {
}
@ -5997,6 +6001,9 @@ named "customerPreferenceDao" and then falls back to a primary type match for th
@@ -5997,6 +6001,9 @@ named "customerPreferenceDao" and then falls back to a primary type match for th
// ...
}
----
<1> The `context` field is injected based on the known resolvable dependency type:
@ -6005,14 +6012,15 @@ named "customerPreferenceDao" and then falls back to a primary type match for th
@@ -6005,14 +6012,15 @@ named "customerPreferenceDao" and then falls back to a primary type match for th
@Resource
private lateinit var customerPreferenceDao: CustomerPreferenceDao
// The context field is injected based on the known resolvable dependency
// type: ApplicationContext
@Resource
private lateinit var context: ApplicationContext
private lateinit var context: ApplicationContext // <1>
// ...
}
----
<1> The `context` field is injected based on the known resolvable dependency type:
`ApplicationContext`.
[[beans-value-annotations]]
=== Using `@Value`
@ -6341,24 +6349,27 @@ is meta-annotated with `@Component`, as the following example shows:
@@ -6341,24 +6349,27 @@ is meta-annotated with `@Component`, as the following example shows:
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component // Causes @Service to be treated in the same way as @Component
@Component // <1>
public @interface Service {
// ...
}
----
<1> The `Component` causes `@Service` to be treated in the same way as `@Component`.
@Component // Causes @Service to be treated in the same way as @Component
@Component // <1>
annotation class Service {
// ...
}
----
<1> The `Component` causes `@Service` to be treated in the same way as `@Component`.
You can also combine meta-annotations to create "`composed annotations`". For example,
the `@RestController` annotation from Spring MVC is composed of `@Controller` and
@ -7779,20 +7790,23 @@ To enable component scanning, you can annotate your `@Configuration` class as fo
@@ -7779,20 +7790,23 @@ To enable component scanning, you can annotate your `@Configuration` class as fo
.Java
----
@Configuration
@ComponentScan(basePackages = "com.acme") // This annotation enables component scanning
@ -69,16 +69,19 @@ The following code introduces the SpEL API to evaluate the literal string expres
@@ -69,16 +69,19 @@ The following code introduces the SpEL API to evaluate the literal string expres
.Java
----
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression("'Hello World'"); // The value of the message variable is 'Hello World'
val exp = parser.parseExpression("'Hello World'") // The value of the message variable is 'Hello World'
val exp = parser.parseExpression("'Hello World'") // <1>
val message = exp.value as String
----
<1> The value of the message variable is `'Hello World'`.
The SpEL classes and interfaces you are most likely to use are located in the
@ -100,18 +103,19 @@ In the following example of method invocation, we call the `concat` method on th
@@ -100,18 +103,19 @@ In the following example of method invocation, we call the `concat` method on th
.Java
----
ExpressionParser parser = new SpelExpressionParser();
val exp = parser.parseExpression("'Hello World'.concat('!')")
// The value of message is now 'Hello World!'
val exp = parser.parseExpression("'Hello World'.concat('!')") // <1>
val message = exp.value as String
----
<1> The value of `message` is now 'Hello World!'.
The following example of calling a JavaBean property calls the `String` property `Bytes`:
@ -121,18 +125,21 @@ The following example of calling a JavaBean property calls the `String` property
@@ -121,18 +125,21 @@ The following example of calling a JavaBean property calls the `String` property
ExpressionParser parser = new SpelExpressionParser();
// invokes 'getBytes()'
Expression exp = parser.parseExpression("'Hello World'.bytes"); // This line converts the literal to a byte array
val exp = parser.parseExpression("'Hello World'.bytes") // This line converts the literal to a byte array
val exp = parser.parseExpression("'Hello World'.bytes") // <1>
val bytes = exp.value as ByteArray
----
<1> This line converts the literal to a byte array.
SpEL also supports nested properties by using the standard dot notation (such as
`prop1.prop2.prop3`) and also the corresponding setting of property values.
@ -146,18 +153,21 @@ The following example shows how to use dot notation to get the length of a liter
@@ -146,18 +153,21 @@ The following example shows how to use dot notation to get the length of a liter
ExpressionParser parser = new SpelExpressionParser();
// invokes 'getBytes().length'
Expression exp = parser.parseExpression("'Hello World'.bytes.length"); // 'Hello World'.bytes.length gives the length of the literal.