2013-05-01 63 views
2

我有POM文件(pom.xml中):如何在spring context.xml中使用pom屬性?

 ... 
    <properties> 
     <certificate-manager.default-client-certDN>Default Client</certificate-manager.default-client-certDN> 
     <certificate-manager.path-to-store>D:\Projects\PPP\apache-tomcat-7.0.29\</certificate-manager.path-to-store> 
     <certificate-manager.store-password>12345</certificate-manager.store-password> 
     <certificate-manager.alias>root</certificate-manager.alias> 
    </properties> 

和屬性文件(my.properties):

certificateManager.defaultClientCertDN=${certificate-manager.default-client-certDN} 
certificateManager.pathToStore=${certificate-manager.path-to-store} 
certificateManager.storePassword=${certificate-manager.store-password} 
certificateManager.alias=${certificate-manager.alias} 

,我想用我的春天的context.xml這個特性(appContext .XML):

<context:property-placeholder location="classpath:my.properties"/> 

    <bean id="certificateManager" class="com.exadel.mdp.security.certificate.CertificateManagerImpl"> 
     <constructor-arg name="defaultClientCertDN" value="${certificateManager.defaultClientCertDN}"/> 
     <constructor-arg name="pathToStore" value="${certificateManager.pathToStore}"/> 
     <constructor-arg name="storePassword" value="${certificateManager.storePassword}"/> 
     <constructor-arg name="alias" value="${certificateManager.alias}"/> 
    </bean> 

當我試圖運行的應用程序,我得到一個異常:

ERROR: org.springframework.web.context.ContextLoader - Context initialization failed 
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'certificateManager' defined in class path resource [appContext.xml]: Could not resolve placeholder 'certificateManager.defaultClientCertDN' in string value [${certificateManager.defaultClientCertDN}] 
    at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:209) 
    at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.processProperties(PropertySourcesPlaceholderConfigurer.java:174) 
    at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.postProcessBeanFactory(PropertySourcesPlaceholderConfigurer.java:151) 
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:686) 
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:661) 

回答

相關問題