【发布时间】:2013-03-15 15:12:49
【问题描述】:
我有一个问题要解决: 1)我们的项目使用 Spring JavaConfig 方法(所以没有 xml 文件) 2)我需要创建自定义范围,xml中的示例如下所示:
<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
<property name="scopes">
<map>
<entry key="workflow">
<bean
class="com.amazonaws.services.simpleworkflow.flow.spring.WorkflowScope" />
</entry>
</map>
</property>
我用 JavaConfig 发现它看起来像这样:
@Bean
public CustomScopeConfigurer customScope () {
CustomScopeConfigurer configurer = new CustomScopeConfigurer ();
Map<String, Object> workflowScope = new HashMap<String, Object>();
workflowScope.put("workflow", new WorkflowScope ());
configurer.setScopes(workflowScope);
return configurer;
}
如果我的假设有误,请纠正我。
3) 我需要将我的类注释为 @Component (scope="workflow") xml 配置再次看起来像这样:
<bean id="activitiesClient" class="aws.flow.sample.MyActivitiesClientImpl" scope="workflow"/>
所以基本上问题是 - 我的假设是正确的使用 @Component (scope="workflow") 还是预期以其他方式?
谢谢
【问题讨论】:
-
我刚刚收到警告
@Bean method getWorkflowScope is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues.仅供参考,您的方法应该是@Bean public static CustomScopeConfigurer
标签: spring configuration annotations scope