今天写邮件系统导入了一个新的properties文件,以前只有的单个properties文件是数据库连接的驱动文件,今天导入了个新的文件mail.properties。出现了下面的问题。
Invalid bean definition with name ‘javaMailSender’ defined in class
path resource [applicationContext.xml]: Could not resolve placeholder
‘mail.smtp.host’ in value “ m a i l . s m t p . h o s t " ; n e s t e d e x c e p t i o n i s j a v a . l a n g . I l l e g a l A r g u m e n t E x c e p t i o n : C o u l d n o t r e s o l v e p l a c e h o l d e r ′ m a i l . s m t p . h o s t ′ i n v a l u e " {mail.smtp.host}"; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'mail.smtp.host' in value " mail.smtp.host";nestedexceptionisjava.lang.IllegalArgumentException:Couldnotresolveplaceholder′mail.smtp.host′invalue"{mail.smtp.host}”
解决办法:
向下面代码那样给每一个context中加上 ignore-unresolvable=“true”
<context:property-placeholder location="classpath:mail.properties" ignore-unresolvable="true"/>
<context:property-placeholder location="classpath:db.properties" ignore-unresolvable="true"/>
这样问题就解决了。