spring boot 项目启动之前 做接口端口检测
前言
这里主要是用代码的方式实现在服务启动之前,服务先尝试连接一下需要被连接的服务,如果连接失败的话,服务本身启动失败,并且打印启动失败日志
一、springboot启动类中添加websocket连接
1.在启动类中添加方法
public class BacksystemApplication {
private static final Logger logger= LoggerFactory.getLogger(BacksystemApplication.class);
public static void main(String[] args) {
Socket socket=new Socket();
SocketAddress socketAddress=new InetSocketAddress("192.172.0.99",9001);
try {
socket.connect(socketAddress);
SpringApplication.run(BacksystemApplicat