【问题标题】:Could not resolve placeholder 'spring.mail.host' in value "${spring.mail.host}"无法解析值“${spring.mail.host}”中的占位符“spring.mail.host”
【发布时间】:2018-09-04 05:17:06
【问题描述】:

Bilan-application-context.xml:

    <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
        <property name="host" value="${spring.mail.host}"/>
        <property name="port" value="${spring.mail.port}"/>
<!--         <property name="username" value="howtodoinjava@gmail.com"/>
        <property name="password" value="password"/> -->
        <property name="javaMailProperties">
            <props>
                <prop key="mail.transport.protocol">${mail.transport.protocol}</prop>
                <prop key="mail.smtp.auth">${mail.smtp.auth}</prop>
                <prop key="mail.smtp.starttls.enable">${mail.smtp.starttls.enable}</prop>
                <prop key="mail.debug">${mail.debug}</prop>
            </props>
        </property>
    </bean>

错误是:

org.springframework.beans.factory.BeanDefinitionStoreException: 
Invalid bean definition with name 'mailSender' defined in class path resource 
[bilan-application-context.xml]: Could not resolve placeholder 'spring.mail.host' in value "${spring.mail.host}"; 
nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.mail.host' in value "${spring.mail.host}"

我找不到上述问题的解决方案。

【问题讨论】:

    标签: spring-boot


    【解决方案1】:

    您在Bilan-application-context.xml 内将您的属性文件显示为:

    <context:property-placeholder location="classpath:spring/mail.properties"/>
    
    • 请注意,我的示例中使用了mail.properties,您需要确保根据您的属性将其更改为适当的路径和正确的文件名。

    【讨论】:

      猜你喜欢
      • 2017-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多