Hi there,
How to read configured parameter in managed bean constructor?
I tried as following but got error:
@Inject
public CamProcessEngine(Configuration configuration) {
log.info("Getting Camunda BPM Process Engine");
String engineName = configuration.getConfig(CamConfig.class)
.getEngineName();
this.engine = BpmPlatform.getProcessEngineService().getProcessEngine(engineName);
}
Error message:
2018-03-29 16:20:10.429 ERROR [localhost-startStop-2] com.haulmont.cuba.core.sys.AbstractWebAppContextLoader - Error initializing application
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'camProcessEngine' defined in URL [jar:file:/C:/Users/thuyl/Desktop/camunda-bpm-tomcat-7.8.0/server/apache-tomcat-8.0.47/webapps/cambpm-core/WEB-INF/lib/cambpm-core-7.8.0.jar!/vn/tki/cambpm/core/CamProcessEngine.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [vn.tki.cambpm.core.CamProcessEngine]: Constructor threw exception; nested exception is java.lang.IllegalStateException: Application context is not initialized
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:279) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1193) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1095) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) ~[spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93) ~[spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at com.haulmont.cuba.core.sys.CubaClassPathXmlApplicationContext.<init>(CubaClassPathXmlApplicationContext.java:27) ~[cuba-global-6.8.5.jar:6.8.5]
at com.haulmont.cuba.core.sys.CubaCoreApplicationContext.<init>(CubaCoreApplicationContext.java:26) ~[cuba-core-6.8.5.jar:6.8.5]
at com.haulmont.cuba.core.sys.AppContextLoader.createApplicationContext(AppContextLoader.java:89) ~[cuba-core-6.8.5.jar:6.8.5]
at com.haulmont.cuba.core.sys.AppContextLoader.createApplicationContext(AppContextLoader.java:35) ~[cuba-core-6.8.5.jar:6.8.5]
at com.haulmont.cuba.core.sys.AbstractAppContextLoader.initAppContext(AbstractAppContextLoader.java:62) ~[cuba-global-6.8.5.jar:6.8.5]
at com.haulmont.cuba.core.sys.AbstractWebAppContextLoader.contextInitialized(AbstractWebAppContextLoader.java:75) ~[cuba-global-6.8.5.jar:6.8.5]
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4853) [catalina.jar:8.0.47]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5314) [catalina.jar:8.0.47]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145) [catalina.jar:8.0.47]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:753) [catalina.jar:8.0.47]
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:729) [catalina.jar:8.0.47]
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717) [catalina.jar:8.0.47]
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:976) [catalina.jar:8.0.47]
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1853) [catalina.jar:8.0.47]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [na:1.8.0_162]
at java.util.concurrent.FutureTask.run(Unknown Source) [na:1.8.0_162]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_162]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_162]
at java.lang.Thread.run(Unknown Source) [na:1.8.0_162]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [vn.tki.cambpm.core.CamProcessEngine]: Constructor threw exception; nested exception is java.lang.IllegalStateException: Application context is not initialized
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:154) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:122) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:271) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
... 32 common frames omitted
Caused by: java.lang.IllegalStateException: Application context is not initialized
at com.haulmont.cuba.core.global.AppBeans.getApplicationContext(AppBeans.java:124) ~[cuba-global-6.8.5.jar:6.8.5]
at com.haulmont.cuba.core.global.AppBeans.get(AppBeans.java:75) ~[cuba-global-6.8.5.jar:6.8.5]
at com.haulmont.cuba.core.sys.ConfigPersisterImpl.getConfigStorageAPI(ConfigPersisterImpl.java:71) ~[cuba-core-6.8.5.jar:6.8.5]
at com.haulmont.cuba.core.sys.ConfigPersisterImpl.getProperty(ConfigPersisterImpl.java:44) ~[cuba-core-6.8.5.jar:6.8.5]
at com.haulmont.cuba.core.config.ConfigGetter.getProperty(ConfigGetter.java:110) ~[cuba-global-6.8.5.jar:6.8.5]
at com.haulmont.cuba.core.config.ConfigGetter.getProperty(ConfigGetter.java:95) ~[cuba-global-6.8.5.jar:6.8.5]
at com.haulmont.cuba.core.config.ConfigGetter.invoke(ConfigGetter.java:67) ~[cuba-global-6.8.5.jar:6.8.5]
at com.haulmont.cuba.core.config.ConfigHandler.invoke(ConfigHandler.java:79) ~[cuba-global-6.8.5.jar:6.8.5]
at com.sun.proxy.$Proxy309.getEngineName(Unknown Source) ~[na:na]
at vn.tki.cambpm.core.CamProcessEngine.<init>(CamProcessEngine.java:77) ~[cambpm-core-7.8.0.jar:na]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_162]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[na:1.8.0_162]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[na:1.8.0_162]
at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[na:1.8.0_162]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
... 34 common frames omitted