无法解析值为“ $ {spring.mail.host}”的占位符“ spring.mail.host”

时间:2018-09-04 05:17:07

标签: spring-boot

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

我找不到上述解决方案。

1 个答案:

答案 0 :(得分:0)

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

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