@ManagedProperty equivalent in Spring

北城余情 提交于 2021-02-10 18:57:07

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!