CDI object not proxyable with injected constructor

前端 未结 5 1951
广开言路
广开言路 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:02

    This example might help you :

    @ApplicationScoped
    public class Config {
    
        private String defaultConfigPath;  
    
        @Inject
        public Config(ConfigLocator configLocator) {
           this.defaultConfigPath = configLocator.getPath();
           doStuff();
        }
    
        // create a no-args constructor which is required for any scoped bean.
        public Config() {
        }
    
    }
    

    You need to have a public non-args constructor in the @ApplicationScoped bean.

    Note : The bean for this class will created only once and is maintained for the entire life of an application. This bean will shared among all the managed beans. @ApplicationScoped beans are singleton in nature.

    The mentioned issue:

    Caused by: org.jboss.weld.exceptions.UnproxyableResolutionException: WELD-001435: Normal scoped bean class xx.Config is not proxyable because it has no no-args constructor - Managed Bean [class xx.Config] with qualifiers [@Default @Named @Any].
    

    The possible reason for this is that a non-dependent scoped bean is required to provide a public no-args constructor for CDI, so that it can pick up the desired proxy bean at runtime.

提交回复
热议问题