Replaced use of EmbeddedValueResolverAware with ConfigurableBeanFactory's resolveEmbeddedValue in order to avoid a package cycle with the org.springframework.context package

Issue: SPR-10021
This commit is contained in:
Juergen Hoeller 2012-11-25 20:18:59 +01:00
parent 202b15e19b
commit df76f1497a
2 changed files with 20 additions and 9 deletions

View File

@ -20,7 +20,9 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import org.springframework.beans.annotation.AnnotationBeanUtils;
import org.springframework.context.EmbeddedValueResolverAware;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.jmx.export.metadata.InvalidMetadataException;
import org.springframework.jmx.export.metadata.JmxAttributeSource;
@ -45,13 +47,21 @@ import org.springframework.util.StringValueResolver;
* @see org.springframework.jmx.export.annotation.ManagedAttribute
* @see org.springframework.jmx.export.annotation.ManagedOperation
*/
public class AnnotationJmxAttributeSource implements JmxAttributeSource, EmbeddedValueResolverAware {
public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFactoryAware {
private StringValueResolver embeddedValueResolver;
public void setEmbeddedValueResolver(StringValueResolver resolver) {
this.embeddedValueResolver = resolver;
public void setBeanFactory(final BeanFactory beanFactory) {
if (beanFactory instanceof ConfigurableBeanFactory) {
// Not using EmbeddedValueResolverAware in order to avoid a spring-context dependency:
// ConfigurableBeanFactory and its resolveEmbeddedValue live in the spring-beans module.
this.embeddedValueResolver = new StringValueResolver() {
public String resolveStringValue(String strVal) {
return ((ConfigurableBeanFactory) beanFactory).resolveEmbeddedValue(strVal);
}
};
}
}

View File

@ -16,11 +16,10 @@
package org.springframework.jmx.export.annotation;
import org.springframework.context.EmbeddedValueResolverAware;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.jmx.export.MBeanExporter;
import org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler;
import org.springframework.jmx.export.naming.MetadataNamingStrategy;
import org.springframework.util.StringValueResolver;
/**
* Convenient subclass of Spring's standard {@link MBeanExporter},
@ -34,7 +33,7 @@ import org.springframework.util.StringValueResolver;
* @author Juergen Hoeller
* @since 2.5
*/
public class AnnotationMBeanExporter extends MBeanExporter implements EmbeddedValueResolverAware {
public class AnnotationMBeanExporter extends MBeanExporter {
private final AnnotationJmxAttributeSource annotationSource =
new AnnotationJmxAttributeSource();
@ -65,8 +64,10 @@ public class AnnotationMBeanExporter extends MBeanExporter implements EmbeddedVa
this.metadataNamingStrategy.setDefaultDomain(defaultDomain);
}
public void setEmbeddedValueResolver(StringValueResolver resolver) {
this.annotationSource.setEmbeddedValueResolver(resolver);
@Override
public void setBeanFactory(BeanFactory beanFactory) {
super.setBeanFactory(beanFactory);
this.annotationSource.setBeanFactory(beanFactory);
}
}