外部プロパティ ファイルを使用して、Spring Application Context 構成ファイルに一部の Bean を設定しようとしています。${} プロパティを使用せず、以下の jpaVendorAdapter クラス プロパティをハードコードすると、ファイルがログ ファイルに読み込まれていることがわかります。プロパティ ファイルに依存し、class="${jpa.vendor.adapter}" 表記を使用すると、「クラスで定義された 'jpaVendorAdapter' という名前の Bean のクラス [${jpa.vendor.adapter}] が見つかりません」パス リソース [spring/applicationContext.xml]; 例外。ファイルは実行時にクラスパス上に明確にあり、必要になった後にロードされたように見えます。私もこの<contextroperty-placeholder/>
アプローチを使用してみましたが、同じ例外がありました。Spring バージョン 3.2.2.RELEASE を使用していますが、何かアイデアはありますか?
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>
プロジェクトのプロパティ
jpa.vendor.adapter=org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter
例外
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [${jpa.vendor.adapter}] for bean with name 'jpaVendorAdapter' defined in class path resource [spring/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: ${jpa.vendor.adapter}
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1269) ~[spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:578) ~[spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1338) ~[spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:356) [spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:327) [spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:435) [spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:624) [spring-context-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461) [spring-context-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389) [spring-web-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294) [spring-web-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) [spring-web-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.jboss.resteasy.plugins.spring.SpringContextLoaderListener.contextInitialized(SpringContextLoaderListener.java:44) [resteasy-spring-2.3.5.Final.jar:na]
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:740) [jetty-server-7.6.8.v20121106.jar:7.6.8.v20121106]
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:238) [jetty-servlet-7.6.8.v20121106.jar:7.6.8.v20121106]
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1238) [jetty-webapp-7.6.8.v20121106.jar:7.6.8.v20121106]
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:683) [jetty-server-7.6.8.v20121106.jar:7.6.8.v20121106]
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:480) [jetty-webapp-7.6.8.v20121106.jar:7.6.8.v20121106]
at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:256) [jetty-maven-plugin-7.6.8.v20121106.jar:7.6.8.v20121106]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64) [jetty-util-7.6.8.v20121106.jar:7.6.8.v20121106]
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229) [jetty-server-7.6.8.v20121106.jar:7.6.8.v20121106]
at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:172) [jetty-server-7.6.8.v20121106.jar:7.6.8.v20121106]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64) [jetty-util-7.6.8.v20121106.jar:7.6.8.v20121106]
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229) [jetty-server-7.6.8.v20121106.jar:7.6.8.v20121106]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64) [jetty-util-7.6.8.v20121106.jar:7.6.8.v20121106]
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95) [jetty-server-7.6.8.v20121106.jar:7.6.8.v20121106]
at org.eclipse.jetty.server.Server.doStart(Server.java:275) [jetty-server-7.6.8.v20121106.jar:7.6.8.v20121106]
at org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:65) [jetty-maven-plugin-7.6.8.v20121106.jar:7.6.8.v20121106]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64) [jetty-util-7.6.8.v20121106.jar:7.6.8.v20121106]
at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:511) [jetty-maven-plugin-7.6.8.v20121106.jar:7.6.8.v20121106]
at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:364) [jetty-maven-plugin-7.6.8.v20121106.jar:7.6.8.v20121106]
at org.mortbay.jetty.plugin.JettyRunMojo.execute(JettyRunMojo.java:521) [jetty-maven-plugin-7.6.8.v20121106.jar:7.6.8.v20121106]
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) [maven-core-3.0.3.jar:3.0.3]
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) [maven-core-3.0.3.jar:3.0.3]
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) [maven-core-3.0.3.jar:3.0.3]
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) [maven-core-3.0.3.jar:3.0.3]
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) [maven-core-3.0.3.jar:3.0.3]
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) [maven-core-3.0.3.jar:3.0.3]
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) [maven-core-3.0.3.jar:3.0.3]
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) [maven-core-3.0.3.jar:3.0.3]
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319) [maven-core-3.0.3.jar:3.0.3]
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) [maven-core-3.0.3.jar:3.0.3]
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) [maven-embedder-3.0.3.jar:3.0.3]
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) [maven-embedder-3.0.3.jar:3.0.3]
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) [maven-embedder-3.0.3.jar:3.0.3]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_51]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_51]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_51]
at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_51]
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) [plexus-classworlds-2.4.jar:na]
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) [plexus-classworlds-2.4.jar:na]
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) [plexus-classworlds-2.4.jar:na]
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) [plexus-classworlds-2.4.jar:na]
Caused by: java.lang.ClassNotFoundException: ${jpa.vendor.adapter}
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50) ~[na:na]
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244) ~[na:na]
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230) ~[na:na]
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:430) ~[na:na]
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:383) ~[na:na]
at org.springframework.util.ClassUtils.forName(ClassUtils.java:260) ~[spring-core-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:416) ~[spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1290) ~[spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at 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