2

我有 pom 文件(pom.xml):

      ...
  <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}

我想在我的 spring 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) 
4

1 回答 1

1

我相信您使用Maven 属性插件并将其配置为初始化阶段。Spring 独立地从属性文件中读取。

于 2013-05-01T09:54:29.137 回答