Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为springbean分配注释_Java_Spring_Jsf_Annotations_Javabeans - Fatal编程技术网

Java 为springbean分配注释

Java 为springbean分配注释,java,spring,jsf,annotations,javabeans,Java,Spring,Jsf,Annotations,Javabeans,我对注释是新手,我正在尝试jsf(2.0)spring(3.1)集成,我可以集成这两个框架,但jsf中没有viewScope,因为它不可用。我想使用注释在jsf managedBean中自动注入Springbean,但我不能,因为spring只支持会话和请求范围bean 我使用一个检索bean的Util类。“SprigUtil.getBean('bean')”。并在需要时手动检索SpringBean 我想这样做 @CustomAnnotation('beanTest') private Bean

我对注释是新手,我正在尝试jsf(2.0)spring(3.1)集成,我可以集成这两个框架,但jsf中没有viewScope,因为它不可用。我想使用注释在jsf managedBean中自动注入Springbean,但我不能,因为spring只支持会话和请求范围bean

我使用一个检索bean的Util类。“SprigUtil.getBean('bean')”。并在需要时手动检索SpringBean

我想这样做

@CustomAnnotation('beanTest')
private Bean bean;
@assign('House')
private String place;
因此,bean属性将与BeanTestbean一起设置

我的目标(撇开春天不谈)是知道如何做到这一点

@CustomAnnotation('beanTest')
private Bean bean;
@assign('House')
private String place;
当我调用
getMethod
获取“House”时。instance.getPlace(),返回“House”

注: 我知道@Autowired,但我不能使用它,因为ViewScope在SpringJSF集成中不可用

我读过关于手动实现视图范围的内容,但是我想尝试一种不同的解决方案

编辑:

我的脸配置:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd"
    version="2.1">
    <application>
        <el-resolver>             org.springframework.web.jsf.el.SpringBeanFacesELResolver
        </el-resolver>
    </application>
</faces-config>
我的豆子

@Component
@Scope("request")//I need to use @Scope("view") but it doesn't exist
public ProductBean implements Serializable{
@Autowired
ProductService productoService;

}

如果我使用jsf注释@ManagedBean和@ViewScoped productService未注入(为null)

您可以使用

对于名为B的spring组件

@ManagedProperty("#{B}")
private B b;

public void setB(B b) {
this.b = b;
}
应该有用

对于您发布的代码,组件是一个Spring注释,要使用ViewScoped,您必须使用ManagedBean注释对类进行注释:

@ManagedBean
@ViewScoped
public ProductBean implements Serializable {
@ManagedProperty("#{productService}")
private ProductService productService;

public void setProductService(ProductService productService) {
    this.productService = productService;
  }
 }

您可能想查看下面的链接以更好地理解JSF 2.0中的作用域,您能展示一下您的spring应用程序上下文吗?我会试试。。。。但是当我在bean spring中使用@ViewScoped时,不要注入任何东西是的,在JSF2 spring集成中,支持5种类型的bean作用域:单例、原型、请求、会话和globalSession。我需要ViewScope,但我不能使用它,如果我使用@ViewScope注释,mb中的每一个自动连接都不起作用。我指的是您的特殊情况:)您是否设法将spring组件注入到一个即RequestScope的托管bean中?是的!,如果我使用一个请求范围(@scope('request')),一切正常。在我的例子中,我实现了集成,但是我需要在viewScope中注入一个mb的Springbean,但是viewScope不可用。因此,我正在尝试开始工作。我认为您混合了spring和jsf作用域,您可以发布托管bean和Springbean代码吗?