@SessionScoped CDI bean is a different Instance when injected

两盒软妹~` 提交于 2019-12-01 06:52:23

Looks like your test doesn't work:

testModel object = model.TestModel@689a6064
New version : Version 2, Object : model.TestModel@61606aa6

So you update an instance which is not the same as the one linked to the session (another request not reusing the same session I'd say)

Siliarus

You are doing it right. That is, from CDI perspective, you made no mistake and what you want is perfectly legit and should work (assuming you solved the problem of multiple sessions, which you did).

I just tried this with my own piece of code and it works as expected. You can check it on GitHub. The sample is more or less identical to yours.

However, I am running Wildfly 10 and therefore Weld 2.3 which comes with it (Weld being a reference impl of CDI). While you are running TomEE which contains OpenWebBeans (another CDI implementation).

To me it seems like you either missed some TomEE/OWB specific configuration (unrealistic scenario) or, more likely, you found a bug. In any case, if I were you, I would try asking on their forums or creating an issue in their tracking system because, once again, there is imho nothing wrong with your bean/servlet setup.

We have @SessionScope annotation in both JSF & CDI. Please review whether the annotation you are using in your old project is from JSF or from CDI. Find more on the difference between the annotation from JSF & CDI

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