Java 未能加载ApplicationContext
我正在尝试从eclipse中运行junit测试,并且遇到“加载ApplicationContext失败”异常。原因是它试图加载一个使用另一个spring配置中定义的变量的spring配置。例如: common-beans.xml使用${domain}和${realm}Java 未能加载ApplicationContext,java,eclipse,spring,Java,Eclipse,Spring,我正在尝试从eclipse中运行junit测试,并且遇到“加载ApplicationContext失败”异常。原因是它试图加载一个使用另一个spring配置中定义的变量的spring配置。例如: common-beans.xml使用${domain}和${realm} 这些在config2.xml中定义为: <bean id="AppConfigHelper" class="AppConfigHelper"> <property name="appName" value
这些在config2.xml中定义为:
<bean id="AppConfigHelper" class="AppConfigHelper">
<property name="appName" value="Service"/>
<property name="domain" value="unittest"/>
<property name="realm" value="asdf"/>
<property name="root" value="./build/private/unittestroot"/>
</bean>
java.lang.IllegalStateException:未能加载ApplicationContext
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
原因:org.springframework.beans.factory.BeanDefinitionStoreException:URL[文件:spring配置/common/common beans.xml]中定义了名为“bucketPartitionMapper”的无效bean定义:无法解析占位符“域”
如何使其工作?错误表明,Spring无法解析“域”占位符。这意味着,在common-beans.xml中,您正在使用${domain},但Spring无法找到该占位符的值。粘贴的代码仅为AppConfigHelper的域属性设置域属性,而未设置占位符 要设置占位符,请创建名为application.properties的文件,并使其包含以下内容: domain=此处的\u domain\u 然后,您需要在应用程序中设置PropertyPlaceHolderConfigure,如下所示:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>application.properties</value>
</property>
</bean>
应用程序属性
以下是一些帮助您解决问题的资源:
及