CDI object not proxyable with injected constructor

前端 未结 5 1959
广开言路
广开言路 2021-02-20 01:07

When trying to inject arguments into the constructor of a CDI bean (ApplicationScoped), I\'m encountering the following issue:

Caused by: org.jboss.weld.exceptio         


        
5条回答
  •  醉话见心
    2021-02-20 02:00

    Splitting in interface and implementation won't solve the problem completely. The Problem is that the interface will not be ApplicationScoped, because an ApplicationScoped Bean needs a Default "no args" Construcutor, to be proxyable. Like this it will always create a new instance of the implementation. So the implementation behaves like a @Dependent annotated bean.

    If you want to solve it this way, you need to use a method with @PostConstruct to handle the inject of the argument and only use a non arg constructor.

提交回复
热议问题