diff --git a/org.springframework.context/src/main/java/org/springframework/context/EmbeddedValueResolverAware.java b/org.springframework.context/src/main/java/org/springframework/context/EmbeddedValueResolverAware.java new file mode 100644 index 00000000000..7749230f676 --- /dev/null +++ b/org.springframework.context/src/main/java/org/springframework/context/EmbeddedValueResolverAware.java @@ -0,0 +1,39 @@ +/* + * Copyright 2002-2010 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.context; + +import org.springframework.util.StringValueResolver; + +/** + * Interface to be implemented by any object that wishes to be notified of a + * StringValueResolver for the resolution of embedded definition values. + * + *
This is an alternative to a full ConfigurableBeanFactory dependency via the
+ * ApplicationContextAware/BeanFactoryAware interfaces.
+ *
+ * @author Juergen Hoeller
+ * @since 3.0.3
+ * @see org.springframework.beans.factory.config.ConfigurableBeanFactory#resolveEmbeddedValue
+ */
+public interface EmbeddedValueResolverAware {
+
+ /**
+ * Set the StringValueResolver to use for resolving embedded definition values.
+ */
+ void setEmbeddedValueResolver(StringValueResolver resolver);
+
+}
diff --git a/org.springframework.context/src/main/java/org/springframework/context/support/ApplicationContextAwareProcessor.java b/org.springframework.context/src/main/java/org/springframework/context/support/ApplicationContextAwareProcessor.java
index 7e1da6a5e56..d40ca72323d 100644
--- a/org.springframework.context/src/main/java/org/springframework/context/support/ApplicationContextAwareProcessor.java
+++ b/org.springframework.context/src/main/java/org/springframework/context/support/ApplicationContextAwareProcessor.java
@@ -22,11 +22,14 @@ import java.security.PrivilegedAction;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.EmbeddedValueResolverAware;
import org.springframework.context.MessageSourceAware;
import org.springframework.context.ResourceLoaderAware;
+import org.springframework.util.StringValueResolver;
/**
* {@link org.springframework.beans.factory.config.BeanPostProcessor}
@@ -86,6 +89,10 @@ class ApplicationContextAwareProcessor implements BeanPostProcessor {
}
private void invokeAwareInterfaces(Object bean) {
+ if (bean instanceof EmbeddedValueResolverAware) {
+ ((EmbeddedValueResolverAware) bean).setEmbeddedValueResolver(
+ new EmbeddedValueResolver(this.applicationContext.getBeanFactory()));
+ }
if (bean instanceof ResourceLoaderAware) {
((ResourceLoaderAware) bean).setResourceLoader(this.applicationContext);
}
@@ -104,4 +111,18 @@ class ApplicationContextAwareProcessor implements BeanPostProcessor {
return bean;
}
+
+ private static class EmbeddedValueResolver implements StringValueResolver {
+
+ private final ConfigurableBeanFactory beanFactory;
+
+ public EmbeddedValueResolver(ConfigurableBeanFactory beanFactory) {
+ this.beanFactory = beanFactory;
+ }
+
+ public String resolveStringValue(String strVal) {
+ return this.beanFactory.resolveEmbeddedValue(strVal);
+ }
+ }
+
}
diff --git a/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/JodaDateTimeFormatAnnotationFormatterFactory.java b/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/JodaDateTimeFormatAnnotationFormatterFactory.java
index 51eeeddae2d..227729ad52b 100644
--- a/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/JodaDateTimeFormatAnnotationFormatterFactory.java
+++ b/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/JodaDateTimeFormatAnnotationFormatterFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2009 the original author or authors.
+ * Copyright 2002-2010 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.
@@ -31,12 +31,14 @@ import org.joda.time.ReadableInstant;
import org.joda.time.ReadablePartial;
import org.joda.time.format.DateTimeFormatter;
+import org.springframework.context.EmbeddedValueResolverAware;
import org.springframework.format.AnnotationFormatterFactory;
import org.springframework.format.Parser;
import org.springframework.format.Printer;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.DateTimeFormat.ISO;
import org.springframework.util.StringUtils;
+import org.springframework.util.StringValueResolver;
/**
* Formats fields annotated with the {@link DateTimeFormat} annotation.
@@ -46,9 +48,12 @@ import org.springframework.util.StringUtils;
* @since 3.0
* @see DateTimeFormat
*/
-public final class JodaDateTimeFormatAnnotationFormatterFactory implements AnnotationFormatterFactory