spring boot在启动项目之后执行的实现方法

如果是在springboot启动过程中调用实现方法的话,实现方法里的不能读取到application.properties配置文件里的配置信息

具体实现代码如下

 1 import java.io.IOException;
 2 import java.util.concurrent.TimeoutException;
 3 
 4 import org.springframework.beans.factory.annotation.Autowired;
 5 import org.springframework.context.ApplicationListener;
 6 import org.springframework.context.annotation.Configuration;
 7 import org.springframework.context.event.ContextRefreshedEvent;
 8 
 9 import com.rabbitmq.client.ConsumerCancelledException;
10 import com.rabbitmq.client.ShutdownSignalException;
11 import com.yarlung.service.rabbitmq.CustomerMQ;
12 
13 @Configuration
14 public class ApplicationStartup implements ApplicationListener<ContextRefreshedEvent>{ 
15      @Autowired
16      private CustomerMQ customerMQ;
17      
18      @Override
19      public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {  //项目启动后,执行启动消费者方法
20          try {
21             customerMQ.customer();   //消费者的实现方法
22         } catch (ShutdownSignalException | ConsumerCancelledException | IOException | TimeoutException
23                 | InterruptedException e) {
24             // TODO Auto-generated catch block
25             e.printStackTrace();
26         }
27      }
28      
29 }

 

转载于:https://www.cnblogs.com/dianfu537/p/9013891.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值