java - How to unified hibernate config file to only 1 file? -
i trying use 1 hibernate config file in project can easy change datasource easily.
the initial configuration in hibernateutil used audit logging comment /* initial config */
read hibernate.cfg.xml file class path.
after modification, if replace datasource string value, working fine. want place datasource values in config.property , used it.
however on startup, server throws error.
is there anyway can work around?
console error log:
org.springframework.beans.factory.beancreationexception: error creating bean name 'hibernateutil' defined in vfs resource ["/d:/wildfly/standalone/deployments/project.war/web-inf/classes/com/demo/common/hibernateutil.class"]: instantiation of bean failed; nested exception java.lang.exceptionininitializererror @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.instantiatebean(abstractautowirecapablebeanfactory.java:1155) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbeaninstance(abstractautowirecapablebeanfactory.java:1099) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:513) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:483) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:306) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:230) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:302) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:197) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:761) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:866) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:542) @ org.springframework.web.context.contextloader.configureandrefreshwebapplicationcontext(contextloader.java:443) @ org.springframework.web.context.contextloader.initwebapplicationcontext(contextloader.java:325) @ org.springframework.web.context.contextloaderlistener.contextinitialized(contextloaderlistener.java:107) @ io.undertow.servlet.core.applicationlisteners.contextinitialized(applicationlisteners.java:187) @ io.undertow.servlet.core.deploymentmanagerimpl$1.call(deploymentmanagerimpl.java:200) @ io.undertow.servlet.core.deploymentmanagerimpl$1.call(deploymentmanagerimpl.java:171) @ io.undertow.servlet.core.servletrequestcontextthreadsetupaction$1.call(servletrequestcontextthreadsetupaction.java:42) @ io.undertow.servlet.core.contextclassloadersetupaction$1.call(contextclassloadersetupaction.java:43) @ io.undertow.servlet.api.legacythreadsetupactionwrapper$1.call(legacythreadsetupactionwrapper.java:44) @ io.undertow.servlet.api.legacythreadsetupactionwrapper$1.call(legacythreadsetupactionwrapper.java:44) @ io.undertow.servlet.api.legacythreadsetupactionwrapper$1.call(legacythreadsetupactionwrapper.java:44) @ io.undertow.servlet.api.legacythreadsetupactionwrapper$1.call(legacythreadsetupactionwrapper.java:44) @ io.undertow.servlet.api.legacythreadsetupactionwrapper$1.call(legacythreadsetupactionwrapper.java:44) @ io.undertow.servlet.api.legacythreadsetupactionwrapper$1.call(legacythreadsetupactionwrapper.java:44) @ io.undertow.servlet.core.deploymentmanagerimpl.deploy(deploymentmanagerimpl.java:234) @ org.wildfly.extension.undertow.deployment.undertowdeploymentservice.startcontext(undertowdeploymentservice.java:100) @ org.wildfly.extension.undertow.deployment.undertowdeploymentservice$1.run(undertowdeploymentservice.java:82) @ java.util.concurrent.executors$runnableadapter.call(executors.java:511) @ java.util.concurrent.futuretask.run(futuretask.java:266) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) @ java.lang.thread.run(thread.java:745) @ org.jboss.threads.jbossthread.run(jbossthread.java:320) caused by: java.lang.exceptionininitializererror @ com.demo.common.hibernateutil.buildsessionfactory(hibernateutil.java:34) @ com.demo.common.hibernateutil.<clinit>(hibernateutil.java:15) @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:62) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45) @ java.lang.reflect.constructor.newinstance(constructor.java:423) @ org.springframework.beans.beanutils.instantiateclass(beanutils.java:142) @ org.springframework.beans.factory.support.simpleinstantiationstrategy.instantiate(simpleinstantiationstrategy.java:89) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.instantiatebean(abstractautowirecapablebeanfactory.java:1147) ... 33 more caused by: java.lang.nullpointerexception @ java.util.hashtable.put(hashtable.java:459) @ java.util.properties.setproperty(properties.java:166) @ org.hibernate.cfg.configuration.setproperty(configuration.java:210) @ com.demo.common.hibernateutil.buildsessionfactory(hibernateutil.java:24) ... 41 more 14:08:01,666 error [org.jboss.msc.service.fail] (serverservice thread pool -- 71) msc000001: failed start service jboss.undertow.deployment.default-server.default-host./project: org.jboss.msc.service.startexception in service jboss.undertow.deployment.default-server.default-host./project: java.lang.runtimeexception: org.springframework.beans.factory.beancreationexception: error creating bean name 'hibernateutil' defined in vfs resource ["/d:/wildfly/standalone/deployments/project.war/web-inf/classes/com/demo/common/hibernateutil.class"]: instantiation of bean failed; nested exception java.lang.exceptionininitializererror @ org.wildfly.extension.undertow.deployment.undertowdeploymentservice$1.run(undertowdeploymentservice.java:85) @ java.util.concurrent.executors$runnableadapter.call(executors.java:511) @ java.util.concurrent.futuretask.run(futuretask.java:266) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) @ java.lang.thread.run(thread.java:745) @ org.jboss.threads.jbossthread.run(jbossthread.java:320) caused by: java.lang.runtimeexception: org.springframework.beans.factory.beancreationexception: error creating bean name 'hibernateutil' defined in vfs resource ["/d:/wildfly/standalone/deployments/project.war/web-inf/classes/com/demo/common/hibernateutil.class"]: instantiation of bean failed; nested exception java.lang.exceptionininitializererror @ io.undertow.servlet.core.deploymentmanagerimpl.deploy(deploymentmanagerimpl.java:236) @ org.wildfly.extension.undertow.deployment.undertowdeploymentservice.startcontext(undertowdeploymentservice.java:100) @ org.wildfly.extension.undertow.deployment.undertowdeploymentservice$1.run(undertowdeploymentservice.java:82) ... 6 more caused by: org.springframework.beans.factory.beancreationexception: error creating bean name 'hibernateutil' defined in vfs resource ["/d:/wildfly/standalone/deployments/project.war/web-inf/classes/com/demo/common/hibernateutil.class"]: instantiation of bean failed; nested exception java.lang.exceptionininitializererror @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.instantiatebean(abstractautowirecapablebeanfactory.java:1155) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbeaninstance(abstractautowirecapablebeanfactory.java:1099) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:513) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:483) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:306) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:230) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:302) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:197) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:761) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:866) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:542) @ org.springframework.web.context.contextloader.configureandrefreshwebapplicationcontext(contextloader.java:443) @ org.springframework.web.context.contextloader.initwebapplicationcontext(contextloader.java:325) @ org.springframework.web.context.contextloaderlistener.contextinitialized(contextloaderlistener.java:107) @ io.undertow.servlet.core.applicationlisteners.contextinitialized(applicationlisteners.java:187) @ io.undertow.servlet.core.deploymentmanagerimpl$1.call(deploymentmanagerimpl.java:200) @ io.undertow.servlet.core.deploymentmanagerimpl$1.call(deploymentmanagerimpl.java:171) @ io.undertow.servlet.core.servletrequestcontextthreadsetupaction$1.call(servletrequestcontextthreadsetupaction.java:42) @ io.undertow.servlet.core.contextclassloadersetupaction$1.call(contextclassloadersetupaction.java:43) @ io.undertow.servlet.api.legacythreadsetupactionwrapper$1.call(legacythreadsetupactionwrapper.java:44) @ io.undertow.servlet.api.legacythreadsetupactionwrapper$1.call(legacythreadsetupactionwrapper.java:44) @ io.undertow.servlet.api.legacythreadsetupactionwrapper$1.call(legacythreadsetupactionwrapper.java:44) @ io.undertow.servlet.api.legacythreadsetupactionwrapper$1.call(legacythreadsetupactionwrapper.java:44) @ io.undertow.servlet.api.legacythreadsetupactionwrapper$1.call(legacythreadsetupactionwrapper.java:44) @ io.undertow.servlet.api.legacythreadsetupactionwrapper$1.call(legacythreadsetupactionwrapper.java:44) @ io.undertow.servlet.core.deploymentmanagerimpl.deploy(deploymentmanagerimpl.java:234) ... 8 more caused by: java.lang.exceptionininitializererror @ com.demo.common.hibernateutil.buildsessionfactory(hibernateutil.java:34) @ com.demo.common.hibernateutil.<clinit>(hibernateutil.java:15) @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:62) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45) @ java.lang.reflect.constructor.newinstance(constructor.java:423) @ org.springframework.beans.beanutils.instantiateclass(beanutils.java:142) @ org.springframework.beans.factory.support.simpleinstantiationstrategy.instantiate(simpleinstantiationstrategy.java:89) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.instantiatebean(abstractautowirecapablebeanfactory.java:1147) ... 33 more caused by: java.lang.nullpointerexception @ java.util.hashtable.put(hashtable.java:459) @ java.util.properties.setproperty(properties.java:166) @ org.hibernate.cfg.configuration.setproperty(configuration.java:210) @ com.demo.common.hibernateutil.buildsessionfactory(hibernateutil.java:24) ... 41 more 14:08:01,669 error [org.jboss.as.controller.management-operation] (controller boot thread) wflyctl0013: operation ("deploy") failed - address: ([("deployment" => "project.war")]) - failure description: { "wflyctl0080: failed services" => {"jboss.undertow.deployment.default-server.default-host./project" => "org.jboss.msc.service.startexception in service jboss.undertow.deployment.default-server.default-host./project: java.lang.runtimeexception: org.springframework.beans.factory.beancreationexception: error creating bean name 'hibernateutil' defined in vfs resource [\"/d:/wildfly/standalone/deployments/project.war/web-inf/classes/com/demo/common/hibernateutil.class\"]: instantiation of bean failed; nested exception java.lang.exceptionininitializererror caused by: java.lang.runtimeexception: org.springframework.beans.factory.beancreationexception: error creating bean name 'hibernateutil' defined in vfs resource [\"/d:/wildfly/standalone/deployments/project.war/web-inf/classes/com/demo/common/hibernateutil.class\"]: instantiation of bean failed; nested exception java.lang.exceptionininitializererror caused by: org.springframework.beans.factory.beancreationexception: error creating bean name 'hibernateutil' defined in vfs resource [\"/d:/wildfly/standalone/deployments/project.war/web-inf/classes/com/demo/common/hibernateutil.class\"]: instantiation of bean failed; nested exception java.lang.exceptionininitializererror caused by: java.lang.exceptionininitializererror caused by: java.lang.nullpointerexception"}, "wflyctl0412: required services not installed:" => ["jboss.undertow.deployment.default-server.default-host./project"], "wflyctl0180: services missing/unavailable dependencies" => undefined }
hibernateutil class used audit logging. applicationcontext-hibernate.xml file main file used through project.
@component public class hibernateutil { @value("${database.datasource}") private static string datasource; private static final sessionfactory sessionfactory = buildsessionfactory(); @bean(name = "sessionfactory") private static sessionfactory buildsessionfactory() { try { // create sessionfactory hibernate.cfg.xml configuration configuration = new configuration().configure(); configuration.setproperty("hibernate.connection.datasource", datasource); configuration.addresource("com/demo/domain/auditlog.hbm.xml"); return configuration.buildsessionfactory(); /* initial config */ // return new configuration().configure().buildsessionfactory(); } catch (throwable ex) { // make sure log exception, might swallowed system.err.println("initial sessionfactory creation failed." + ex); throw new exceptionininitializererror(ex); } } public static sessionfactory getsessionfactory() { return sessionfactory; } }
applicationcontext-hibernate.xml
<!-- use datasource setup in server (wildfly) --> <bean id="datasource" class="org.springframework.jndi.jndiobjectfactorybean"> <property name="jndiname"> <value>java:/projectds</value> </property> </bean> <bean id="sessionfactory" class="org.springframework.orm.hibernate5.localsessionfactorybean"> <property name="datasource" ref="datasource" /> <property name="hibernateproperties"> <props> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.dialect">org.hibernate.dialect.sqlserver2012dialect</prop> <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.singletonehcacheregionfactory </prop> <prop key="hibernate.cache.use_second_level_cache">true</prop> <prop key="hibernate.cache.use_query_cache">true</prop> <prop key="hibernate.jdbc.batch_size">50</prop> <prop key="hibernate.order_inserts">true</prop> <prop key="hibernate.order_updates">true</prop> <prop key="hibernate.connection.release_mode">after_transaction</prop> <prop key="hibernate.c3p0.min_size">5</prop> <prop key="hibernate.c3p0.max_size">20</prop> <prop key="hibernate.c3p0.timeout">300</prop> <prop key="hibernate.c3p0.max_statements">50</prop> </props> </property> <property name="entityinterceptor"> <bean class="com.demo.common.custominterceptor"/> </property> <!-- scan whole folder --> <property name="mappinglocations" value="classpath:com/demo/domain/*.hbm.xml" /> </bean>
config.properties
database.datasource = java:/projectds
Comments
Post a Comment