重构启动逻辑,移除CommandLineRunner接口,改为使用ApplicationReadyEvent事件监听器

This commit is contained in:
lin 2026-05-08 09:56:35 +08:00
parent 6f1f8d0d60
commit 6c4734ff29
10 changed files with 33 additions and 48 deletions

View File

@ -23,7 +23,6 @@ import java.nio.file.Files;
*/
@Slf4j
@Configuration
@Order(value=15)
public class CivilCodeFileConf implements CommandLineRunner {
@Autowired

View File

@ -8,10 +8,9 @@ import com.genersoft.iot.vmp.gb28181.transmit.ISIPProcessorObserver;
import com.genersoft.iot.vmp.utils.EnvUtil;
import gov.nist.javax.sip.SipProviderImpl;
import gov.nist.javax.sip.SipStackImpl;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
@ -24,8 +23,7 @@ import java.util.concurrent.ConcurrentHashMap;
@Slf4j
@Component
@Order(value=10)
public class SipLayer implements CommandLineRunner {
public class SipLayer{
@Autowired
private SipConfig sipConfig;
@ -40,8 +38,8 @@ public class SipLayer implements CommandLineRunner {
private final Map<String, SipProviderImpl> udpSipProviderMap = new ConcurrentHashMap<>();
private final List<String> monitorIps = new ArrayList<>();
@Override
public void run(String... args) {
@PostConstruct
public void onApplicationReady(){
if (ObjectUtils.isEmpty(sipConfig.getIp())) {
try {
// 获得本机的所有网络接口

View File

@ -43,9 +43,8 @@ import gov.nist.javax.sip.message.SIPResponse;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@ -65,8 +64,7 @@ import java.util.concurrent.TimeUnit;
*/
@Slf4j
@Service
@Order(value=16)
public class DeviceServiceImpl implements IDeviceService, CommandLineRunner {
public class DeviceServiceImpl implements IDeviceService {
@Autowired
private ISIPCommander sipCommander;
@ -129,8 +127,8 @@ public class DeviceServiceImpl implements IDeviceService, CommandLineRunner {
return deviceMapper.getDeviceByDeviceId(deviceId);
}
@Override
public void run(String... args) throws Exception {
@EventListener(ApplicationReadyEvent.class)
public void onApplicationReady(){
// 清理数据库不存在但是 redis 中存在的数据
List<Device> devicesInDb = getAll();

View File

@ -34,7 +34,8 @@ import org.locationtech.jts.geom.Point;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -49,7 +50,7 @@ import java.util.concurrent.atomic.AtomicReference;
@Slf4j
@Service
public class GbChannelServiceImpl implements IGbChannelService, CommandLineRunner {
public class GbChannelServiceImpl implements IGbChannelService {
@Autowired
private EventPublisher eventPublisher;
@ -81,8 +82,8 @@ public class GbChannelServiceImpl implements IGbChannelService, CommandLineRunne
private final GeometryFactory geometryFactory = new GeometryFactory();
@Override
public void run(String... args) throws Exception {
@EventListener(ApplicationReadyEvent.class)
public void onApplicationReady() {
// 启动时重新发布抽稀图层
List<CommonGBChannel> channelList = commonGBChannelMapper.queryAllWithPosition();
Map<Integer, List<CommonGBChannel>> zoomCameraMap = new ConcurrentHashMap<>();

View File

@ -39,9 +39,8 @@ import com.github.pagehelper.PageInfo;
import gov.nist.javax.sip.message.SIPResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@ -62,8 +61,7 @@ import java.util.concurrent.TimeUnit;
*/
@Slf4j
@Service
@Order(value=15)
public class PlatformServiceImpl implements IPlatformService, CommandLineRunner {
public class PlatformServiceImpl implements IPlatformService {
@Autowired
private PlatformMapper platformMapper;
@ -116,8 +114,8 @@ public class PlatformServiceImpl implements IPlatformService, CommandLineRunner
@Autowired
private PlatformStatusTaskRunner statusTaskRunner;
@Override
public void run(String... args) throws Exception {
@EventListener(ApplicationReadyEvent.class)
public void onApplicationReady(){
// 查找国标推流
List<SendRtpInfo> sendRtpItems = redisCatchStorage.queryAllSendRTPServer();

View File

@ -6,7 +6,8 @@ import com.genersoft.iot.vmp.gb28181.service.IGroupService;
import com.genersoft.iot.vmp.gb28181.service.IRegionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@ -21,7 +22,7 @@ import java.util.concurrent.TimeUnit;
@Slf4j
@Component
public class CatalogDataManager implements CommandLineRunner {
public class CatalogDataManager{
@Autowired
private IDeviceChannelService deviceChannelService;
@ -209,8 +210,8 @@ public class CatalogDataManager implements CommandLineRunner {
return false;
}
@Override
public void run(String... args) throws Exception {
@EventListener(ApplicationReadyEvent.class)
public void onApplicationReady(){
// 启动时清理旧的数据
redisTemplate.delete(key);
}

View File

@ -18,13 +18,7 @@ import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.timeout.IdleStateHandler;
import io.netty.util.concurrent.Future;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;
import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.TimeUnit;

View File

@ -30,12 +30,12 @@ import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.PostConstruct;
import jakarta.servlet.ServletOutputStream;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.ftpserver.usermanager.impl.BaseUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
@ -89,9 +89,9 @@ public class jt1078ServiceImpl implements Ijt1078Service {
@Autowired
private FtpDownloadManager downloadManager;
// 服务启动后五分钟内没有尽量连接的设备设置为离线
@PostConstruct
public void init(){
// 服务启动后五分钟内没有连接的设备设置为离线
@EventListener(ApplicationReadyEvent.class)
public void onApplicationReady(){
// 检查session与在线终端是是否对应 不对应则设置终端离线
List<JTDevice> deviceList = jtDeviceMapper.getDeviceList(null, true);
if (deviceList.isEmpty()) {

View File

@ -7,9 +7,9 @@ import com.genersoft.iot.vmp.media.event.mediaServer.MediaServerChangeEvent;
import com.genersoft.iot.vmp.media.service.IMediaServerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.core.annotation.Order;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import java.util.List;
@ -19,8 +19,7 @@ import java.util.List;
*/
@Slf4j
@Component
@Order(value=12)
public class MediaServerConfig implements CommandLineRunner {
public class MediaServerConfig{
@Autowired
private ApplicationEventPublisher applicationEventPublisher;
@ -35,8 +34,8 @@ public class MediaServerConfig implements CommandLineRunner {
private UserSetting userSetting;
@Override
public void run(String... strings) throws Exception {
@EventListener(ApplicationReadyEvent.class)
public void onApplicationReady(){
// 清理所有在线节点的缓存信息
mediaServerService.clearMediaServerForOnline();
MediaServer mediaSerItemInConfig = mediaConfig.buildMediaSer();

View File

@ -255,11 +255,8 @@ export default {
},
stopPlay: function(row) {
this.$store.dispatch('streamProxy/stopPlay', row.id)
.then((data) => {
this.$refs.devicePlayer.openDialog('streamPlay', null, null, {
streamInfo: data,
hasAudio: true
})
.then(() => {
this.getStreamProxyList()
})
.catch((error) => {
this.$message({