I'm using Spring 3.1 JSF 2.2.
Annoting Bean with ViewScoped introduced by JSF 2.2 not work.
@javax.inject.Named
@javax.faces.view.ViewScoped
public class TestBean {
@PostConstruct
public void init(){sysout("Why spring invoke this when initializing context :-( ");}
}
In my applicationContext.xml there is an annotation component-scan tag
<context:component-scan base-package="com.test"/>
Spring 3.1 detect and deal with CDI annotation but @javax.faces.view.ViewScoped not work. I know there is another solution by creating my own ViewScoped implementation but i want to know why @javax.faces.view.ViewScoped not work
最好的解决方案是删除spring并使用Java EE实现的CDI
You should notice that JSF annotations will nor work for Spring beans, because JSF beans located in different context.
But view scope implementation is pretty simple. I've created an artifact to solve this problem.
See my github javaplugs/spring-jsf repository.
javax.faces.view.ViewScoped will only work for JSF Managed Bean and not for CDI.
Use javax.faces.bean.ManagedBean annotation if you want to have a correct behavior with View scope instead of javax.inject.Named.
Regards
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.