在春季相当于@ManagedProperty [英] @ManagedProperty equivalent in Spring
问题描述
我将Spring用于我的DI. 是否有@ManagedProperty的等效项?我想将值从一个视图作用域的bean注入到下一页的另一个视图中.
I am using Spring for my DI. Is there an equivalent of @ManagedProperty? I want to inject the value from one view scoped bean into another one on the next page.
例如
@Component
@Scope("view")
public class Page1Bean(){
private String value;
}
@Component
@Scope("view")
public class Page2Bean(){
@ManagedProperty(value = #{page1Bean}") //doesnt work in Spring
private Page1Bean bean;
}
推荐答案
@Resource
或@Autowired
应该可以. @Resource
是Java EE实现,@Autowired
是spring特定的注释.我现在找不到参考,但是似乎我读过一次,更喜欢@Resource
而不是@Autowired
.
@Resource
or @Autowired
should work. @Resource
is the Java EE implementation, @Autowired
is the spring specific annotation. I can't find the reference now, but it seems like I read once to prefer @Resource
over @Autowired
.
这是我发现的博客文章,内容涉及@Inject
与@Resource
与@Autowired
http://blogs.sourceallies. com/2011/08/spring-injection-with-resource-and-autowired/#more-2350
here's a blog post I found that talks about @Inject
vs. @Resource
vs. @Autowired
http://blogs.sourceallies.com/2011/08/spring-injection-with-resource-and-autowired/#more-2350
这篇关于在春季相当于@ManagedProperty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!