java - Spring PropertyPlaceholderConfigurer Issue to Load A Properties File -
i'm trying use external properties file populate of beans in spring application context configuration file. when don't use ${} properties , hardcode jpavendoradapter class property below, can see file loaded in log file. if u rely on properties file , use class="${jpa.vendor.adapter}" notation, cannot find class [${jpa.vendor.adapter}] bean name 'jpavendoradapter' defined in class path resource [spring/applicationcontext.xml]; exception. file definetly on classpath @ runtime, seems loaded after needed. i've tried using <contextroperty-placeholder/>
approach, got same exception. i'm using spring version 3.2.2.release, ideas?
applicationcontext.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:task="http://www.springframework.org/schema/task" xsi:schemalocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"> <bean class="org.springframework.beans.factory.config.propertyplaceholderconfigurer"> <property name="location"> <value>classpath:runtime/project.properties</value> </property> </bean> <bean id="jpavendoradapter" class="${jpa.vendor.adapter}"> <property name="showsql" value="true" /> <property name="generateddl" value="true" /> <property name="databaseplatform" value="org.hibernate.dialect.oracledialect" /> </bean> </beans>
project.properties
jpa.vendor.adapter=org.springframework.orm.jpa.vendor.hibernatejpavendoradapter
exception
org.springframework.beans.factory.cannotloadbeanclassexception: cannot find class [${jpa.vendor.adapter}] bean name 'jpavendoradapter' defined in class path resource [spring/applicationcontext.xml]; nested exception java.lang.classnotfoundexception: ${jpa.vendor.adapter} @ org.springframework.beans.factory.support.abstractbeanfactory.resolvebeanclass(abstractbeanfactory.java:1269) ~[spring-beans-3.2.2.release.jar:3.2.2.release] @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.predictbeantype(abstractautowirecapablebeanfactory.java:578) ~[spring-beans-3.2.2.release.jar:3.2.2.release] @ org.springframework.beans.factory.support.abstractbeanfactory.isfactorybean(abstractbeanfactory.java:1338) ~[spring-beans-3.2.2.release.jar:3.2.2.release] @ org.springframework.beans.factory.support.defaultlistablebeanfactory.dogetbeannamesfortype(defaultlistablebeanfactory.java:356) [spring-beans-3.2.2.release.jar:3.2.2.release] @ org.springframework.beans.factory.support.defaultlistablebeanfactory.getbeannamesfortype(defaultlistablebeanfactory.java:327) [spring-beans-3.2.2.release.jar:3.2.2.release] @ org.springframework.beans.factory.support.defaultlistablebeanfactory.getbeansoftype(defaultlistablebeanfactory.java:435) [spring-beans-3.2.2.release.jar:3.2.2.release] @ org.springframework.context.support.abstractapplicationcontext.invokebeanfactorypostprocessors(abstractapplicationcontext.java:624) [spring-context-3.2.2.release.jar:3.2.2.release] @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:461) [spring-context-3.2.2.release.jar:3.2.2.release] @ org.springframework.web.context.contextloader.configureandrefreshwebapplicationcontext(contextloader.java:389) [spring-web-3.2.2.release.jar:3.2.2.release] @ org.springframework.web.context.contextloader.initwebapplicationcontext(contextloader.java:294) [spring-web-3.2.2.release.jar:3.2.2.release] @ org.springframework.web.context.contextloaderlistener.contextinitialized(contextloaderlistener.java:112) [spring-web-3.2.2.release.jar:3.2.2.release] @ org.jboss.resteasy.plugins.spring.springcontextloaderlistener.contextinitialized(springcontextloaderlistener.java:44) [resteasy-spring-2.3.5.final.jar:na] @ org.eclipse.jetty.server.handler.contexthandler.startcontext(contexthandler.java:740) [jetty-server-7.6.8.v20121106.jar:7.6.8.v20121106] @ org.eclipse.jetty.servlet.servletcontexthandler.startcontext(servletcontexthandler.java:238) [jetty-servlet-7.6.8.v20121106.jar:7.6.8.v20121106] @ org.eclipse.jetty.webapp.webappcontext.startcontext(webappcontext.java:1238) [jetty-webapp-7.6.8.v20121106.jar:7.6.8.v20121106] @ org.eclipse.jetty.server.handler.contexthandler.dostart(contexthandler.java:683) [jetty-server-7.6.8.v20121106.jar:7.6.8.v20121106] @ org.eclipse.jetty.webapp.webappcontext.dostart(webappcontext.java:480) [jetty-webapp-7.6.8.v20121106.jar:7.6.8.v20121106] @ org.mortbay.jetty.plugin.jettywebappcontext.dostart(jettywebappcontext.java:256) [jetty-maven-plugin-7.6.8.v20121106.jar:7.6.8.v20121106] @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:64) [jetty-util-7.6.8.v20121106.jar:7.6.8.v20121106] @ org.eclipse.jetty.server.handler.handlercollection.dostart(handlercollection.java:229) [jetty-server-7.6.8.v20121106.jar:7.6.8.v20121106] @ org.eclipse.jetty.server.handler.contexthandlercollection.dostart(contexthandlercollection.java:172) [jetty-server-7.6.8.v20121106.jar:7.6.8.v20121106] @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:64) [jetty-util-7.6.8.v20121106.jar:7.6.8.v20121106] @ org.eclipse.jetty.server.handler.handlercollection.dostart(handlercollection.java:229) [jetty-server-7.6.8.v20121106.jar:7.6.8.v20121106] @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:64) [jetty-util-7.6.8.v20121106.jar:7.6.8.v20121106] @ org.eclipse.jetty.server.handler.handlerwrapper.dostart(handlerwrapper.java:95) [jetty-server-7.6.8.v20121106.jar:7.6.8.v20121106] @ org.eclipse.jetty.server.server.dostart(server.java:275) [jetty-server-7.6.8.v20121106.jar:7.6.8.v20121106] @ org.mortbay.jetty.plugin.jettyserver.dostart(jettyserver.java:65) [jetty-maven-plugin-7.6.8.v20121106.jar:7.6.8.v20121106] @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:64) [jetty-util-7.6.8.v20121106.jar:7.6.8.v20121106] @ org.mortbay.jetty.plugin.abstractjettymojo.startjetty(abstractjettymojo.java:511) [jetty-maven-plugin-7.6.8.v20121106.jar:7.6.8.v20121106] @ org.mortbay.jetty.plugin.abstractjettymojo.execute(abstractjettymojo.java:364) [jetty-maven-plugin-7.6.8.v20121106.jar:7.6.8.v20121106] @ org.mortbay.jetty.plugin.jettyrunmojo.execute(jettyrunmojo.java:521) [jetty-maven-plugin-7.6.8.v20121106.jar:7.6.8.v20121106] @ org.apache.maven.plugin.defaultbuildpluginmanager.executemojo(defaultbuildpluginmanager.java:101) [maven-core-3.0.3.jar:3.0.3] @ org.apache.maven.lifecycle.internal.mojoexecutor.execute(mojoexecutor.java:209) [maven-core-3.0.3.jar:3.0.3] @ org.apache.maven.lifecycle.internal.mojoexecutor.execute(mojoexecutor.java:153) [maven-core-3.0.3.jar:3.0.3] @ org.apache.maven.lifecycle.internal.mojoexecutor.execute(mojoexecutor.java:145) [maven-core-3.0.3.jar:3.0.3] @ org.apache.maven.lifecycle.internal.lifecyclemodulebuilder.buildproject(lifecyclemodulebuilder.java:84) [maven-core-3.0.3.jar:3.0.3] @ org.apache.maven.lifecycle.internal.lifecyclemodulebuilder.buildproject(lifecyclemodulebuilder.java:59) [maven-core-3.0.3.jar:3.0.3] @ org.apache.maven.lifecycle.internal.lifecyclestarter.singlethreadedbuild(lifecyclestarter.java:183) [maven-core-3.0.3.jar:3.0.3] @ org.apache.maven.lifecycle.internal.lifecyclestarter.execute(lifecyclestarter.java:161) [maven-core-3.0.3.jar:3.0.3] @ org.apache.maven.defaultmaven.doexecute(defaultmaven.java:319) [maven-core-3.0.3.jar:3.0.3] @ org.apache.maven.defaultmaven.execute(defaultmaven.java:156) [maven-core-3.0.3.jar:3.0.3] @ org.apache.maven.cli.mavencli.execute(mavencli.java:537) [maven-embedder-3.0.3.jar:3.0.3] @ org.apache.maven.cli.mavencli.domain(mavencli.java:196) [maven-embedder-3.0.3.jar:3.0.3] @ org.apache.maven.cli.mavencli.main(mavencli.java:141) [maven-embedder-3.0.3.jar:3.0.3] @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) ~[na:1.6.0_51] @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39) ~[na:1.6.0_51] @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25) ~[na:1.6.0_51] @ java.lang.reflect.method.invoke(method.java:597) ~[na:1.6.0_51] @ org.codehaus.plexus.classworlds.launcher.launcher.launchenhanced(launcher.java:290) [plexus-classworlds-2.4.jar:na] @ org.codehaus.plexus.classworlds.launcher.launcher.launch(launcher.java:230) [plexus-classworlds-2.4.jar:na] @ org.codehaus.plexus.classworlds.launcher.launcher.mainwithexitcode(launcher.java:409) [plexus-classworlds-2.4.jar:na] @ org.codehaus.plexus.classworlds.launcher.launcher.main(launcher.java:352) [plexus-classworlds-2.4.jar:na] caused by: java.lang.classnotfoundexception: ${jpa.vendor.adapter} @ org.codehaus.plexus.classworlds.strategy.selffirststrategy.loadclass(selffirststrategy.java:50) ~[na:na] @ org.codehaus.plexus.classworlds.realm.classrealm.loadclass(classrealm.java:244) ~[na:na] @ org.codehaus.plexus.classworlds.realm.classrealm.loadclass(classrealm.java:230) ~[na:na] @ org.eclipse.jetty.webapp.webappclassloader.loadclass(webappclassloader.java:430) ~[na:na] @ org.eclipse.jetty.webapp.webappclassloader.loadclass(webappclassloader.java:383) ~[na:na] @ org.springframework.util.classutils.forname(classutils.java:260) ~[spring-core-3.2.2.release.jar:3.2.2.release] @ org.springframework.beans.factory.support.abstractbeandefinition.resolvebeanclass(abstractbeandefinition.java:416) ~[spring-beans-3.2.2.release.jar:3.2.2.release] @ org.springframework.beans.factory.support.abstractbeanfactory.doresolvebeanclass(abstractbeanfactory.java:1290) ~[spring-beans-3.2.2.release.jar:3.2.2.release] @ org.springframework.beans.factory.support.abstractbeanfactory.resolvebeanclass(abstractbeanfactory.java:1261) ~[spring-beans-3.2.2.release.jar:3.2.2.release] ... 51 common frames omitted
try replacing propertyplaceholderconfigurer
bean declaration with
<context:property-placeholder location="classpath:/runtime/project.properties"/>
the above must not work class
attribute.
what can instead implement factorybean
produces class type
<bean id="example" class="com.mycom.factory.jpavendoradapterfactory"> <property name="class" value="${jpa.vendor.adapter}"/> <property name="showsql" value="true" /> <property name="generateddl" value="true" /> <property name="databaseplatform" value="org.hibernate.dialect.oracledialect" /> </bean>
i believe spring automatically call getobject()
on bean , add returned object context. believe example
name generated bean (not factory).
Comments
Post a Comment