qualifying beans in SpringBoot

问题: I have a SpringBoot app. with this class that I use to fake a mail sender in my localhost enviroment @Service @Profile("local") @Qualifier("emailSender") public class Fac...

问题:

I have a SpringBoot app. with this class that I use to fake a mail sender in my localhost enviroment

@Service
@Profile("local")
@Qualifier("emailSender")
public class FackeEmailSender {
private static final Logger logger = LoggerFactory.getLogger(FackeEmailSender.class);

and this other

@Service
@Profile("prod")
public class EmailSender {
    private static final Logger logger = LoggerFactory.getLogger(EmailSender.class);

nevertheless when I start the app. with this profile:

spring.profiles.active=local

I got this error

***************************
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.

and

@Component
class EmailQueueListener implements QueueListener {


    private EmailSender emailSender;


    @Autowired
    void setEmailSender(EmailSender emailSender) {
        this.emailSender = emailSender;
    }
..
}

回答1:

Your EmailSender & FackeEmailSender are not implementing any interface. you can extract EmailSender Interface and then implement that interface for both the beans

  • 发表于 2019-01-18 21:13
  • 阅读 ( 139 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除