问题描述
我正在使用 spring boot 2.0.7 Release
和 spring-boot-starter-mail-2.0.7.Release.
我在类中自动装配 javaMailsender
在 Windows 上工作正常,同时尝试在 Unix
上部署时遇到 belwo 问题
I am autowiring javaMailsender
inside the class working ok on windows while trying to deploy on Unix
getting belwo issue
APPLICATION FAILED TO START
***************************
Description:
Field javaMailSender in com.fti.di.capstock.tran.pub.email.SendEmail required a bean of type 'org.springframework.mail.javamail.JavaMailSender' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'org.springframework.mail.javamail.JavaMailSender' in your configuration.
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessagingException;
import org.springframework.stereotype.Component;
import com.fti.di.capstock.tran.pub.constants.ApplicationFlowConstants;
import com.fti.di.integration.constants.IntegrationConstants;
import com.fti.di.integration.util.StringUtil;
@Component("sendEmail")
public class SendEmail {
@Autowired
private JavaMailSender javaMailSender;
@Autowired
Environment env;
@ServiceActivator
推荐答案
在 Configuration 类中声明一个 JavaMailSender
类型的 @BeanSpring Context 的一部分,例如属于 3rd-party lib 的类,这恰好是您的情况).例如:
Declare a @Bean of the type JavaMailSender
in a Configuration class (This is useful when you want to inject a class which is not part of your Spring Context, like a class that belongs to a 3rd-party lib, which happens to be your case). For example:
@Configuration
public class MyConfig {
@Bean
public JavaMailSender javaMailSender() {
return new JavaMailSender();
}
}
确保您在 application.properties
下也设置了正确的属性.
Make sure that the you have set the right properties under application.properties
as well.
另外,看看这个问题,因为我相信这是重复的(如果不是,我很抱歉)
Also, take a look into this question, as I believe this is a duplicate (if it's not, I am sorry)
这篇关于找不到类型为“org.springframework.mail.javamail.JavaMailSender"的bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!