无法解析值"${spring.mail.host}"中的占位符'spring.mail.host'

  • 本文关键字:mail host spring 占位符 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}"

我找不到上述解决方案。

您将内部的属性文件呈现为Bilan-application-context.xml

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

相关内容

最新更新