在春季相当于@ManagedProperty [英] @ManagedProperty equivalent in Spring

查看:31
本文介绍了在春季相当于@ManagedProperty的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆