Data from @RequestScoped bean is shared in different browsers

筅森魡賤 提交于 2019-11-29 11:44:09
BalusC

You shouldn't manage a single bean by multiple different bean management frameworks like JSF, CDI and Spring. Choose the one or the other. When managing the bean by for example Spring's @Controller, all bean management related annotations of other frameworks like JSF's @ManagedBean and CDI's @Named are ignored.

I don't do Spring and I have no idea why you're using it instead of the standard Java EE 6 API, but the symptoms and documentation indicates that the scope of such a Spring bean indeed defaults to the application scope. You need to specify the bean scope by Spring @Scope annotation. You would also like to remove the JSF bean management annotations since they have no value anymore anyway and would only confuse the developer/maintainer.

@Controller
@Scope("request")
public class MyBean implements Serializable {
    // ...
}

Alternatively, you can also get rid of Spring @Controller annotation and stick to JSF @ManagedBean. You can use @ManagedProperty instead of @Autowired to inject another @ManagedBean instance or even a Spring managed bean (if you have Spring Faces EL resolver configured), or the Java EE standard @EJB to inject an @Stateless or @Stateful instance.

E.g.

@ManagedBean
@RequestScoped
public class MyBean implements Serializable {

    @EJB
    private SomeService service;

    // ...
}

See also:

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