2016-11-16 36 views
0
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.mail.javamail.JavaMailSender com.xxx.service.impl.NotificationServiceImpl.mailSender; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.mail.javamail.JavaMailSender] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 

的applicationContext.xml從3.x升級彈簧4.3.2之後,JavaMailSender的自動裝配和VelocityEngine失敗

<?xml version="1.0" encoding="UTF-8"?> 

http://www.springframework.org/schema/beans/spring-豆-4.3.xsd http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-4.3.xsd http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-4.3.xsd 「 默認延遲實例=」 真「>

<!-- Enable @AspectJ support --> 
<aop:aspectj-autoproxy/> 

<!-- Activates scanning of @Autowired --> 
<context:annotation-config/> 

<!-- Activates scanning of @Service --> 
<context:component-scan base-package="com.xxx.service"/> 

<bean id="userSecurityAdvice" class="com.xxx.service.UserSecurityAdvice"/> 

<bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.Md5PasswordEncoder"/> 

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl" autowire="byName"> 
    <property name="host" value="${mail.host}" /> 
    <property name="port" value="${mail.port}" /> 
    <property name="username" value="${mail.username}" /> 
    <property name="password" value="${mail.password}" /> 
    <property name="javaMailProperties"> 
     <props> 
       <prop key="mail.smtp.auth">${mail.smtp.auth}</prop> 
       <prop key="mail.smtp.starttls.enable">${mail.smtp.starttls.enable}</prop> 
       <prop key="mail.from">${mail.from}</prop> 
      </props> 
    </property> 
</bean> 

<!-- Configure Velocity for sending e-mail --> 
<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean"> 
    <property name="velocityProperties"> 
     <props> 
      <prop key="resource.loader">class</prop> 
      <prop key="class.resource.loader.class"> 
       org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader 
      </prop> 
      <prop key="velocimacro.library"></prop> 
     </props> 
    </property> 
</bean> 

其他依賴關係: - javax.mail - 1.4.7, org.apache.velocity - 中還存在1.7

package com.xxx.service.impl; 
@Service("notificationService") 
public class NotificationServiceImpl implements NotificationService { 
@Autowired 
private JavaMailSender mailSender; 
} 

所有依賴關係正確添加,JavaMailSender類春季上下文-support-xxx.jar,但找不到自動裝配的原因。有人可以幫忙嗎?

回答

0

嘗試從.m2目錄中刪除彈出文件夾。然後更新你的Maven依賴項並重建項目。

+0

這是我做的第一件事,但沒有解決。無論如何感謝回覆 – user3919131