【发布时间】:2020-02-21 08:35:55
【问题描述】:
我正在尝试使用MethodInvokingFactoryBean 来获取com.amazonaws.regions.Region 的实例以用于配置com.amazonaws.services.kinesis.AmazonKinesisClient。我正在 Blueprint、Camel、Karaf 中执行此操作。
<bean id="awsRegion" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass" value="com.amazonaws.regions.RegionUtils"/>
<property name="targetMethod" value="getRegion"/>
<property name="arguments">
<list>
<value>EU-WEST-1</value>
</list>
</property>
</bean>
<bean id="kinesisClient" class="com.amazonaws.services.kinesis.AmazonKinesisClient">
<property name="region" ref="awsRegion"/>
</bean>
这似乎应该可以工作,第一个 bean 创建一个区域,第二个 bean 使用它。
但是,我收到一个错误,看起来 MethodInvokingFactoryBean 只是返回一个自身的实例,而不是 Region。
org.osgi.service.blueprint.container.ComponentDefinitionException: Error setting property: PropertyDescriptor <name: region, getter: null, setter: [class com.amazonaws.AmazonWebServiceClient.setRegion(class com.amazonaws.regions.Region)]
...
Caused by: java.lang.Exception: Unable to convert value org.springframework.beans.factory.config.MethodInvokingFactoryBean@2289c050 to type com.amazonaws.regions.Region
我在 RegionUtils 中调用的方法应该返回一个 Region https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/regions/RegionUtils.html#getRegion-java.lang.String-
我在这个问题中遇到了这种在客户端中获取区域的方法,该解决方案似乎对提问者有效。
【问题讨论】:
-
弹簧和蓝图不要混用,只用蓝图
标签: spring apache-camel spring-bean blueprint-osgi