我有一个SpringBoot应用程序。这个类用来在我的本地主机环境中伪造邮件发件人
@Service
@Profile("local")
@Qualifier("emailSender")
public class FackeEmailSender {
private static final Logger logger = LoggerFactory.getLogger(FackeEmailSender.class);
还有这个
@Service
@Profile("prod")
public class EmailSender {
private static final Logger logger = LoggerFactory.getLogger(EmailSender.class);
但是,当我启动该应用程序时。使用此配置文件:
spring.profiles.active=local
我收到这个错误
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method setEmailSender in com.tdk.jms.EmailQueueListener required a bean of type 'com.tdk.services.EmailSender' that could not be found.
Action:
Consider defining a bean of type 'com.tdk.services.EmailSender' in your configuration.
和
@Component
class EmailQueueListener implements QueueListener {
private EmailSender emailSender;
@Autowired
void setEmailSender(EmailSender emailSender) {
this.emailSender = emailSender;
}
..
}
最佳答案
您的EmailSender
和FackeEmailSender
没有实现任何接口。您可以提取EmailSender接口,然后为两个bean实施该接口