我有一个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;
}
..
}
答案 0 :(得分:2)
您的EmailSender
和FackeEmailSender
没有实现任何接口。您可以提取EmailSender接口,然后为两个bean实施该接口
答案 1 :(得分:1)
您可以尝试使用
@自动连线 私人EmailSender emailSender;
代替在setEmailSender上使用