@ManagedProperty does not work in a CDI managed bean

試著忘記壹切 提交于 2019-12-01 09:28:29
Masudul

@ManagedProperty is managed bean annotaion, that can't be used with CDI. In above code, you used CDI bean i.e. @Named that is default in JSF 2.2. In this case you can't use ManagedProperty. Please read following line copied from Java EE docs of ManagedBean.

If this annotation is present on a class that does not have the ManagedBean annotation, the implementation must take no action on this annotation.

For details see the link:

http://docs.oracle.com/javaee/6/api/javax/faces/bean/ManagedProperty.html

So, use @Inject instead of @ManagedProperty for CDI bean.

@Inject
private User user;

Note that a getter/setter is unnecessary here.

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