“@inject”-ed attribute remains null

前端 未结 2 2127
天涯浪人
天涯浪人 2021-02-19 04:14

I am trying to inject a service into my bean but it is always null. I get the following error: WELD-001000 Error resolving property userBean against base null.

2条回答
  •  鱼传尺愫
    2021-02-19 04:46

    Another alternative is use @PostConstruct method annotation.

    @SessionScoped
    public class UserBean implements Serializable {
        @Inject UserService service;
        private User user;
        public UserBean() {
    
        }
    
       @PostConstruct
        void init(){
            this.user = service.findUser("kaas"); 
        }
    
      }
    

    Read docs

提交回复
热议问题