Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
ea4a766d
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ea4a766d
编写于
2月 17, 2016
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Consistent support for SpEL next to placeholders in annotation attributes
Issue: SPR-13625
上级
e0d7c6be
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
157 addition
and
57 deletion
+157
-57
spring-beans/src/main/java/org/springframework/beans/factory/config/EmbeddedValueResolver.java
...framework/beans/factory/config/EmbeddedValueResolver.java
+59
-0
spring-context/src/main/java/org/springframework/context/EmbeddedValueResolverAware.java
...g/springframework/context/EmbeddedValueResolverAware.java
+4
-2
spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java
...context/annotation/CommonAnnotationBeanPostProcessor.java
+10
-3
spring-context/src/main/java/org/springframework/context/support/ApplicationContextAwareProcessor.java
...ork/context/support/ApplicationContextAwareProcessor.java
+6
-19
spring-context/src/main/java/org/springframework/jmx/export/annotation/AnnotationJmxAttributeSource.java
...k/jmx/export/annotation/AnnotationJmxAttributeSource.java
+5
-10
spring-context/src/test/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessorTests.java
...annotation/ScheduledAnnotationBeanPostProcessorTests.java
+43
-4
spring-jms/src/main/java/org/springframework/jms/annotation/JmsListenerAnnotationBeanPostProcessor.java
...ms/annotation/JmsListenerAnnotationBeanPostProcessor.java
+10
-9
spring-jms/src/main/java/org/springframework/jms/config/MethodJmsListenerEndpoint.java
...springframework/jms/config/MethodJmsListenerEndpoint.java
+20
-10
未找到文件。
spring-beans/src/main/java/org/springframework/beans/factory/config/EmbeddedValueResolver.java
0 → 100644
浏览文件 @
ea4a766d
/*
* Copyright 2002-2016 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.beans.factory.config
;
import
org.springframework.util.StringValueResolver
;
/**
* {@link StringValueResolver} adapter for resolving placeholders and
* expressions against a {@link ConfigurableBeanFactory}.
*
* <p>Note that this adapter resolves expressions as well, in contrast
* to the {@link ConfigurableBeanFactory#resolveEmbeddedValue} method.
* The {@link BeanExpressionContext} used is for the plain bean factory,
* with no scope specified for any contextual objects to access.
*
* @author Juergen Hoeller
* @since 4.3
* @see ConfigurableBeanFactory#resolveEmbeddedValue(String)
* @see ConfigurableBeanFactory#getBeanExpressionResolver()
* @see BeanExpressionContext
*/
public
class
EmbeddedValueResolver
implements
StringValueResolver
{
private
final
BeanExpressionContext
exprContext
;
private
final
BeanExpressionResolver
exprResolver
;
public
EmbeddedValueResolver
(
ConfigurableBeanFactory
beanFactory
)
{
this
.
exprContext
=
new
BeanExpressionContext
(
beanFactory
,
null
);
this
.
exprResolver
=
beanFactory
.
getBeanExpressionResolver
();
}
@Override
public
String
resolveStringValue
(
String
strVal
)
{
String
value
=
this
.
exprContext
.
getBeanFactory
().
resolveEmbeddedValue
(
strVal
);
if
(
this
.
exprResolver
!=
null
&&
value
!=
null
)
{
Object
evaluated
=
this
.
exprResolver
.
evaluate
(
value
,
this
.
exprContext
);
value
=
(
evaluated
!=
null
?
evaluated
.
toString
()
:
null
);
}
return
value
;
}
}
spring-context/src/main/java/org/springframework/context/EmbeddedValueResolverAware.java
浏览文件 @
ea4a766d
/*
* Copyright 2002-201
1
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -29,7 +29,9 @@ import org.springframework.util.StringValueResolver;
* @author Juergen Hoeller
* @author Chris Beams
* @since 3.0.3
* @see org.springframework.beans.factory.config.ConfigurableBeanFactory#resolveEmbeddedValue
* @see org.springframework.beans.factory.config.ConfigurableBeanFactory#resolveEmbeddedValue(String)
* @see org.springframework.beans.factory.config.ConfigurableBeanFactory#getBeanExpressionResolver()
* @see org.springframework.beans.factory.config.EmbeddedValueResolver
*/
public
interface
EmbeddedValueResolverAware
extends
Aware
{
...
...
spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java
浏览文件 @
ea4a766d
...
...
@@ -58,6 +58,7 @@ import org.springframework.beans.factory.annotation.InjectionMetadata;
import
org.springframework.beans.factory.config.AutowireCapableBeanFactory
;
import
org.springframework.beans.factory.config.ConfigurableBeanFactory
;
import
org.springframework.beans.factory.config.DependencyDescriptor
;
import
org.springframework.beans.factory.config.EmbeddedValueResolver
;
import
org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor
;
import
org.springframework.beans.factory.support.RootBeanDefinition
;
import
org.springframework.core.BridgeMethodResolver
;
...
...
@@ -68,6 +69,7 @@ import org.springframework.util.Assert;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.ReflectionUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringValueResolver
;
/**
* {@link org.springframework.beans.factory.config.BeanPostProcessor} implementation
...
...
@@ -181,6 +183,8 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
private
transient
BeanFactory
beanFactory
;
private
transient
StringValueResolver
embeddedValueResolver
;
private
transient
final
Map
<
String
,
InjectionMetadata
>
injectionMetadataCache
=
new
ConcurrentHashMap
<
String
,
InjectionMetadata
>(
256
);
...
...
@@ -274,12 +278,15 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
}
@Override
public
void
setBeanFactory
(
BeanFactory
beanFactory
)
throws
BeansException
{
public
void
setBeanFactory
(
BeanFactory
beanFactory
)
{
Assert
.
notNull
(
beanFactory
,
"BeanFactory must not be null"
);
this
.
beanFactory
=
beanFactory
;
if
(
this
.
resourceFactory
==
null
)
{
this
.
resourceFactory
=
beanFactory
;
}
if
(
beanFactory
instanceof
ConfigurableBeanFactory
)
{
this
.
embeddedValueResolver
=
new
EmbeddedValueResolver
((
ConfigurableBeanFactory
)
beanFactory
);
}
}
...
...
@@ -595,8 +602,8 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
resourceName
=
Introspector
.
decapitalize
(
resourceName
.
substring
(
3
));
}
}
else
if
(
beanFactory
instanceof
ConfigurableBeanFactory
)
{
resourceName
=
((
ConfigurableBeanFactory
)
beanFactory
).
resolveEmbedded
Value
(
resourceName
);
else
if
(
embeddedValueResolver
!=
null
)
{
resourceName
=
embeddedValueResolver
.
resolveString
Value
(
resourceName
);
}
if
(
resourceType
!=
null
&&
Object
.
class
!=
resourceType
)
{
checkResourceType
(
resourceType
);
...
...
spring-context/src/main/java/org/springframework/context/support/ApplicationContextAwareProcessor.java
浏览文件 @
ea4a766d
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -23,7 +23,7 @@ import java.security.PrivilegedAction;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.Aware
;
import
org.springframework.beans.factory.config.BeanPostProcessor
;
import
org.springframework.beans.factory.config.
ConfigurableBeanFactory
;
import
org.springframework.beans.factory.config.
EmbeddedValueResolver
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.context.ApplicationEventPublisherAware
;
import
org.springframework.context.ConfigurableApplicationContext
;
...
...
@@ -61,12 +61,15 @@ class ApplicationContextAwareProcessor implements BeanPostProcessor {
private
final
ConfigurableApplicationContext
applicationContext
;
private
final
StringValueResolver
embeddedValueResolver
;
/**
* Create a new ApplicationContextAwareProcessor for the given context.
*/
public
ApplicationContextAwareProcessor
(
ConfigurableApplicationContext
applicationContext
)
{
this
.
applicationContext
=
applicationContext
;
this
.
embeddedValueResolver
=
new
EmbeddedValueResolver
(
applicationContext
.
getBeanFactory
());
}
...
...
@@ -103,8 +106,7 @@ class ApplicationContextAwareProcessor implements BeanPostProcessor {
((
EnvironmentAware
)
bean
).
setEnvironment
(
this
.
applicationContext
.
getEnvironment
());
}
if
(
bean
instanceof
EmbeddedValueResolverAware
)
{
((
EmbeddedValueResolverAware
)
bean
).
setEmbeddedValueResolver
(
new
EmbeddedValueResolver
(
this
.
applicationContext
.
getBeanFactory
()));
((
EmbeddedValueResolverAware
)
bean
).
setEmbeddedValueResolver
(
this
.
embeddedValueResolver
);
}
if
(
bean
instanceof
ResourceLoaderAware
)
{
((
ResourceLoaderAware
)
bean
).
setResourceLoader
(
this
.
applicationContext
);
...
...
@@ -126,19 +128,4 @@ class ApplicationContextAwareProcessor implements BeanPostProcessor {
return
bean
;
}
private
static
class
EmbeddedValueResolver
implements
StringValueResolver
{
private
final
ConfigurableBeanFactory
beanFactory
;
public
EmbeddedValueResolver
(
ConfigurableBeanFactory
beanFactory
)
{
this
.
beanFactory
=
beanFactory
;
}
@Override
public
String
resolveStringValue
(
String
strVal
)
{
return
this
.
beanFactory
.
resolveEmbeddedValue
(
strVal
);
}
}
}
spring-context/src/main/java/org/springframework/jmx/export/annotation/AnnotationJmxAttributeSource.java
浏览文件 @
ea4a766d
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -27,6 +27,7 @@ import org.springframework.beans.annotation.AnnotationBeanUtils;
import
org.springframework.beans.factory.BeanFactory
;
import
org.springframework.beans.factory.BeanFactoryAware
;
import
org.springframework.beans.factory.config.ConfigurableBeanFactory
;
import
org.springframework.beans.factory.config.EmbeddedValueResolver
;
import
org.springframework.core.annotation.AnnotationUtils
;
import
org.springframework.jmx.export.metadata.InvalidMetadataException
;
import
org.springframework.jmx.export.metadata.JmxAttributeSource
;
...
...
@@ -50,19 +51,13 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFac
@Override
public
void
setBeanFactory
(
final
BeanFactory
beanFactory
)
{
public
void
setBeanFactory
(
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
()
{
@Override
public
String
resolveStringValue
(
String
strVal
)
{
return
((
ConfigurableBeanFactory
)
beanFactory
).
resolveEmbeddedValue
(
strVal
);
}
};
this
.
embeddedValueResolver
=
new
EmbeddedValueResolver
((
ConfigurableBeanFactory
)
beanFactory
);
}
}
@Override
public
org
.
springframework
.
jmx
.
export
.
metadata
.
ManagedResource
getManagedResource
(
Class
<?>
beanClass
)
throws
InvalidMetadataException
{
ManagedResource
ann
=
AnnotationUtils
.
findAnnotation
(
beanClass
,
ManagedResource
.
class
);
...
...
spring-context/src/test/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessorTests.java
浏览文件 @
ea4a766d
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -24,7 +24,9 @@ import java.lang.annotation.Target;
import
java.lang.reflect.Method
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Properties
;
import
java.util.TimeZone
;
...
...
@@ -364,8 +366,8 @@ public class ScheduledAnnotationBeanPostProcessorTests {
properties
.
setProperty
(
"schedules.businessHours"
,
businessHoursCronExpression
);
placeholderDefinition
.
getPropertyValues
().
addPropertyValue
(
"properties"
,
properties
);
BeanDefinition
targetDefinition
=
new
RootBeanDefinition
(
PropertyPlaceholderWithCronTestBean
.
class
);
context
.
registerBeanDefinition
(
"placeholder"
,
placeholderDefinition
);
context
.
registerBeanDefinition
(
"postProcessor"
,
processorDefinition
);
context
.
registerBeanDefinition
(
"placeholder"
,
placeholderDefinition
);
context
.
registerBeanDefinition
(
"target"
,
targetDefinition
);
context
.
refresh
();
...
...
@@ -395,8 +397,8 @@ public class ScheduledAnnotationBeanPostProcessorTests {
properties
.
setProperty
(
"initialDelay"
,
"1000"
);
placeholderDefinition
.
getPropertyValues
().
addPropertyValue
(
"properties"
,
properties
);
BeanDefinition
targetDefinition
=
new
RootBeanDefinition
(
PropertyPlaceholderWithFixedDelayTestBean
.
class
);
context
.
registerBeanDefinition
(
"placeholder"
,
placeholderDefinition
);
context
.
registerBeanDefinition
(
"postProcessor"
,
processorDefinition
);
context
.
registerBeanDefinition
(
"placeholder"
,
placeholderDefinition
);
context
.
registerBeanDefinition
(
"target"
,
targetDefinition
);
context
.
refresh
();
...
...
@@ -427,8 +429,8 @@ public class ScheduledAnnotationBeanPostProcessorTests {
properties
.
setProperty
(
"initialDelay"
,
"1000"
);
placeholderDefinition
.
getPropertyValues
().
addPropertyValue
(
"properties"
,
properties
);
BeanDefinition
targetDefinition
=
new
RootBeanDefinition
(
PropertyPlaceholderWithFixedRateTestBean
.
class
);
context
.
registerBeanDefinition
(
"placeholder"
,
placeholderDefinition
);
context
.
registerBeanDefinition
(
"postProcessor"
,
processorDefinition
);
context
.
registerBeanDefinition
(
"placeholder"
,
placeholderDefinition
);
context
.
registerBeanDefinition
(
"target"
,
targetDefinition
);
context
.
refresh
();
...
...
@@ -450,6 +452,35 @@ public class ScheduledAnnotationBeanPostProcessorTests {
assertEquals
(
3000L
,
task
.
getInterval
());
}
@Test
public
void
expressionWithCron
()
{
String
businessHoursCronExpression
=
"0 0 9-17 * * MON-FRI"
;
BeanDefinition
processorDefinition
=
new
RootBeanDefinition
(
ScheduledAnnotationBeanPostProcessor
.
class
);
BeanDefinition
targetDefinition
=
new
RootBeanDefinition
(
ExpressionWithCronTestBean
.
class
);
context
.
registerBeanDefinition
(
"postProcessor"
,
processorDefinition
);
context
.
registerBeanDefinition
(
"target"
,
targetDefinition
);
Map
<
String
,
String
>
schedules
=
new
HashMap
<
String
,
String
>();
schedules
.
put
(
"businessHours"
,
businessHoursCronExpression
);
context
.
getBeanFactory
().
registerSingleton
(
"schedules"
,
schedules
);
context
.
refresh
();
Object
postProcessor
=
context
.
getBean
(
"postProcessor"
);
Object
target
=
context
.
getBean
(
"target"
);
ScheduledTaskRegistrar
registrar
=
(
ScheduledTaskRegistrar
)
new
DirectFieldAccessor
(
postProcessor
).
getPropertyValue
(
"registrar"
);
@SuppressWarnings
(
"unchecked"
)
List
<
CronTask
>
cronTasks
=
(
List
<
CronTask
>)
new
DirectFieldAccessor
(
registrar
).
getPropertyValue
(
"cronTasks"
);
assertEquals
(
1
,
cronTasks
.
size
());
CronTask
task
=
cronTasks
.
get
(
0
);
ScheduledMethodRunnable
runnable
=
(
ScheduledMethodRunnable
)
task
.
getRunnable
();
Object
targetObject
=
runnable
.
getTarget
();
Method
targetMethod
=
runnable
.
getMethod
();
assertEquals
(
target
,
targetObject
);
assertEquals
(
"x"
,
targetMethod
.
getName
());
assertEquals
(
businessHoursCronExpression
,
task
.
getExpression
());
}
@Test
public
void
propertyPlaceholderForMetaAnnotation
()
{
String
businessHoursCronExpression
=
"0 0 9-17 * * MON-FRI"
;
...
...
@@ -699,6 +730,14 @@ public class ScheduledAnnotationBeanPostProcessorTests {
}
static
class
ExpressionWithCronTestBean
{
@Scheduled
(
cron
=
"#{schedules.businessHours}"
)
public
void
x
()
{
}
}
@Scheduled
(
cron
=
"${schedules.businessHours}"
)
@Target
(
ElementType
.
METHOD
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
...
...
spring-jms/src/main/java/org/springframework/jms/annotation/JmsListenerAnnotationBeanPostProcessor.java
浏览文件 @
ea4a766d
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -36,6 +36,7 @@ import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import
org.springframework.beans.factory.SmartInitializingSingleton
;
import
org.springframework.beans.factory.config.BeanPostProcessor
;
import
org.springframework.beans.factory.config.ConfigurableBeanFactory
;
import
org.springframework.beans.factory.config.EmbeddedValueResolver
;
import
org.springframework.core.MethodIntrospector
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.annotation.AnnotationUtils
;
...
...
@@ -49,6 +50,7 @@ import org.springframework.messaging.handler.annotation.support.MessageHandlerMe
import
org.springframework.messaging.handler.invocation.InvocableHandlerMethod
;
import
org.springframework.util.Assert
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringValueResolver
;
/**
* Bean post-processor that registers methods annotated with {@link JmsListener}
...
...
@@ -95,6 +97,8 @@ public class JmsListenerAnnotationBeanPostProcessor
private
BeanFactory
beanFactory
;
private
StringValueResolver
embeddedValueResolver
;
private
final
MessageHandlerMethodFactoryAdapter
messageHandlerMethodFactory
=
new
MessageHandlerMethodFactoryAdapter
();
private
final
JmsListenerEndpointRegistrar
registrar
=
new
JmsListenerEndpointRegistrar
();
...
...
@@ -146,6 +150,9 @@ public class JmsListenerAnnotationBeanPostProcessor
@Override
public
void
setBeanFactory
(
BeanFactory
beanFactory
)
{
this
.
beanFactory
=
beanFactory
;
if
(
beanFactory
instanceof
ConfigurableBeanFactory
)
{
this
.
embeddedValueResolver
=
new
EmbeddedValueResolver
((
ConfigurableBeanFactory
)
beanFactory
);
}
}
...
...
@@ -243,6 +250,7 @@ public class JmsListenerAnnotationBeanPostProcessor
endpoint
.
setMethod
(
invocableMethod
);
endpoint
.
setMostSpecificMethod
(
mostSpecificMethod
);
endpoint
.
setMessageHandlerMethodFactory
(
this
.
messageHandlerMethodFactory
);
endpoint
.
setEmbeddedValueResolver
(
this
.
embeddedValueResolver
);
endpoint
.
setBeanFactory
(
this
.
beanFactory
);
endpoint
.
setId
(
getEndpointId
(
jmsListener
));
endpoint
.
setDestination
(
resolve
(
jmsListener
.
destination
()));
...
...
@@ -293,15 +301,8 @@ public class JmsListenerAnnotationBeanPostProcessor
}
}
/**
* Resolve the specified value if possible.
* @see ConfigurableBeanFactory#resolveEmbeddedValue
*/
private
String
resolve
(
String
value
)
{
if
(
this
.
beanFactory
instanceof
ConfigurableBeanFactory
)
{
return
((
ConfigurableBeanFactory
)
this
.
beanFactory
).
resolveEmbeddedValue
(
value
);
}
return
value
;
return
(
this
.
embeddedValueResolver
!=
null
?
this
.
embeddedValueResolver
.
resolveStringValue
(
value
)
:
value
);
}
...
...
spring-jms/src/main/java/org/springframework/jms/config/MethodJmsListenerEndpoint.java
浏览文件 @
ea4a766d
...
...
@@ -22,7 +22,9 @@ import java.util.Arrays;
import
org.springframework.aop.framework.AopProxyUtils
;
import
org.springframework.aop.support.AopUtils
;
import
org.springframework.beans.factory.BeanFactory
;
import
org.springframework.beans.factory.BeanFactoryAware
;
import
org.springframework.beans.factory.config.ConfigurableBeanFactory
;
import
org.springframework.beans.factory.config.EmbeddedValueResolver
;
import
org.springframework.core.annotation.AnnotationUtils
;
import
org.springframework.jms.listener.MessageListenerContainer
;
import
org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter
;
...
...
@@ -33,6 +35,7 @@ import org.springframework.messaging.handler.annotation.support.MessageHandlerMe
import
org.springframework.messaging.handler.invocation.InvocableHandlerMethod
;
import
org.springframework.util.Assert
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringValueResolver
;
/**
* A {@link JmsListenerEndpoint} providing the method to invoke to process
...
...
@@ -42,7 +45,7 @@ import org.springframework.util.StringUtils;
* @author Juergen Hoeller
* @since 4.1
*/
public
class
MethodJmsListenerEndpoint
extends
AbstractJmsListenerEndpoint
{
public
class
MethodJmsListenerEndpoint
extends
AbstractJmsListenerEndpoint
implements
BeanFactoryAware
{
private
Object
bean
;
...
...
@@ -52,6 +55,8 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint {
private
MessageHandlerMethodFactory
messageHandlerMethodFactory
;
private
StringValueResolver
embeddedValueResolver
;
private
BeanFactory
beanFactory
;
...
...
@@ -110,12 +115,24 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint {
}
/**
* Set the {@link BeanFactory} to use to resolve expressions (can be null).
* Set a value resolver for embedded placeholders and expressions.
*/
public
void
setEmbeddedValueResolver
(
StringValueResolver
embeddedValueResolver
)
{
this
.
embeddedValueResolver
=
embeddedValueResolver
;
}
/**
* Set the {@link BeanFactory} to use to resolve expressions (can be {@code null}).
*/
@Override
public
void
setBeanFactory
(
BeanFactory
beanFactory
)
{
this
.
beanFactory
=
beanFactory
;
if
(
this
.
embeddedValueResolver
==
null
&&
beanFactory
instanceof
ConfigurableBeanFactory
)
{
this
.
embeddedValueResolver
=
new
EmbeddedValueResolver
((
ConfigurableBeanFactory
)
beanFactory
);
}
}
@Override
protected
MessagingMessageListenerAdapter
createMessageListener
(
MessageListenerContainer
container
)
{
Assert
.
state
(
this
.
messageHandlerMethodFactory
!=
null
,
...
...
@@ -179,15 +196,8 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint {
}
}
/**
* Resolve the specified value if possible.
* @see ConfigurableBeanFactory#resolveEmbeddedValue
*/
private
String
resolve
(
String
value
)
{
if
(
this
.
beanFactory
instanceof
ConfigurableBeanFactory
)
{
return
((
ConfigurableBeanFactory
)
this
.
beanFactory
).
resolveEmbeddedValue
(
value
);
}
return
value
;
return
(
this
.
embeddedValueResolver
!=
null
?
this
.
embeddedValueResolver
.
resolveStringValue
(
value
)
:
value
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录