问题
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.
e.g
@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;
}
回答1:
@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
.
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
来源:https://stackoverflow.com/questions/14130140/managedproperty-equivalent-in-spring