java - Assign spring beans with annotations -
i'm new annotations, i'm trying jsf(2.0) spring (3.1) integration, integrate 2 framewoks don't have viewscope in jsf beacause isn't avaliable. want utilize annotations inject automatically spring beans in jsf managedbean, can't becauso spring suppor sessions , request scope beans.
i utilize util class retrives bean. "sprigutil.getbean('bean')". , manually retirve spring beans when need.
i want this
@customannotation('beantest') private bean bean;
so, bean atributte set beantest bean.
my objective (leaving aside spring) know how this
@assing('house') private string place;
and when phone call getmethod obtain "house". instance.getplace(), homecoming 'house'
note: know @autowired can't utilize because viewscope not avaliable in spring-jsf integration. read implement view scope manually want seek different solution.
edit:
my facesconfig:
my facesconfig:
<?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>
and appcontext
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> <context:component-scan base-package="*" /> </beans>
my spring bean
@component public class productservice{ }
my managed bean
@component @scope("request")//i need utilize @scope("view") doesn't exist public productbean implements serializable{ @autowired productservice productoservice; }
if utilize jsf annotations @managedbean , @viewscoped productservice not injected (is null)
you can inject spring beans view scoped managed beans using @managedproperty
for spring component named b
@managedproperty("#{b}") private b b; public void setb(b b) { this.b = b; }
should work.
as code have posted, component spring annotation, utilize viewscoped must annotate class managedbean annotation:
@managedbean @viewscoped public productbean implements serializable { @managedproperty("#{productservice}") private productservice productservice; public void setproductservice(productservice productservice) { this.productservice = productservice; } }
you might want check out next link improve understand scopes in jsf 2.0 communication in jsf 2.0
java spring jsf annotations javabeans
No comments:
Post a Comment