Spring框架是否可以以注释驱动的方式注入集合?
是否可以使用注释驱动注入执行相同的操作:
<beans> ... <bean id="interceptorsList" class="com.mytest.AnyAction"> <property name="interceptors"> <list> <ref bean="validatorInteceptor"/> <ref bean="profilingInterceptor"/> </list> </property> </bean> </beans>
Is it possible to do the same using annotation-driven injection?
Is it possible to do the same using annotation-driven injection:
<beans> ... <bean id="interceptorsList" class="com.mytest.AnyAction"> <property name="interceptors"> <list> <ref bean="validatorInteceptor"/> <ref bean="profilingInterceptor"/> </list> </property> </bean> </beans>
Is it possible to do the same using annotation-driven injection?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好问题 - 我不这么认为(假设“注释驱动注入”指的是
AnyAction
上的注释)。以下方法可能有效,但我认为 Spring 无法识别
@Resources
注释:无论如何,尝试一下,你永远不会知道。
除此之外,您可以使用
@Configuration
样式配置而不是 XML:Good question - I don't think so (assuming that by "annotation-driven injection" you're referring to annotations on
AnyAction
).It's possible that the following might work, but I don't think Spring recognises the
@Resources
annotation:Give it a try anyway, you never know.
Other than, you can use
@Configuration
-style configuration instead of XML:是的,如果您使用此模式,Spring 将愉快地注入所有已配置的拦截器:
请注意,您可能必须在 context.xml 上配置 default-autowire=byType。我不知道在普通注释配置中是否有替代方案。
Yes, Spring will happily inject all configured interceptors if you use this pattern:
Note that you will probably have to configure default-autowire=byType on your context.xml. I don't know if there's an alternative to this in plain annotation configuration.