其他分享
首页 > 其他分享> > springboot如何在项目启动时初始化资源-ApplicationRunner

springboot如何在项目启动时初始化资源-ApplicationRunner

作者:互联网

 实现ApplicationRunner,并重写run方法即可

@Component
public class InitPortJob implements ApplicationRunner {
 
    private final static Logger logger = LoggerFactory.getLogger(InitPortJob.class);
    //数量待调整
    public static BlockingQueue<Integer>  portQueue = new LinkedBlockingQueue<Integer>(10000);
    
    //@Value("${sip.begin.port}")
    private int beginPort=30000;
 
    //@Value("${sip.end.port}")
    private int endPort=40000;
    
    @Override
    public void run(ApplicationArguments args) throws Exception {
        logger.info("InitPort Begin MinPort:{};MaxPort:{};",beginPort,endPort);
        for (int tempPort = beginPort; tempPort < endPort; tempPort++) {
            if(tempPort%2 == 0) {
                portQueue.offer(tempPort);
            }
        }
    }
}

 

标签:初始化,tempPort,springboot,int,beginPort,private,ApplicationRunner,endPort
来源: https://www.cnblogs.com/Vincent-yuan/p/15468179.html