我想在我的应用程序来实现电子邮件功能,但我不断收到的Spring bean自动装配误差
No matching bean of type [org.springframework.mail.javamail.JavaMailSenderImpl] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.
任何人都可以指出我在做什么错误?
XML配置的bean是:
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<context:annotation-config/>
//...other stuff
<beans:bean id="mailSession" class="org.springframework.jndi.JndiObjectFactoryBean">
<beans:property name="jndiName" value="EmailServer" />
</beans:bean>
<beans:bean id="emailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<beans:property name="session" ref="mailSession"/>
</beans:bean>
EmailServiceImpl类:
@Service
public class EmailServiceImpl implements EmailService {
@Autowired
private JavaMailSenderImpl emailSender;
//more code..
}
我遇到了同样的问题,并且在xml中配置时一切正常。从服务bean emailServiceImpl中删除autowired和@service注释。自动装配在其他豆类中工作正常。我想知道JavaMail中的自动装配有什么问题。 – 2016-01-26 14:38:49