Browse Source

feat:原有tomcat更改为tongweb代码更改

national_dev
coral 2 years ago
parent
commit
27535da07c
  1. 4
      code/smart-community/epmet-auth/src/main/java/com/epmet/AuthApplication.java
  2. 12
      code/smart-community/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/config/shutdown/GracefulShutdownConfig.java
  3. 19
      code/smart-community/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/config/shutdown/GracefulShutdownTongWeb.java
  4. 26
      code/smart-community/epmet-gateway/src/main/java/com/epmet/GatewayApplication.java

4
code/smart-community/epmet-auth/src/main/java/com/epmet/AuthApplication.java

@ -1,8 +1,8 @@
/**
* Copyright (c) 2018 人人开源 All rights reserved.
*
* <p>
* https://www.renren.io
*
* <p>
* 版权所有侵权必究
*/

12
code/smart-community/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/config/shutdown/GracefulShutdownConfig.java

@ -1,13 +1,13 @@
package com.epmet.commons.tools.config.shutdown;
import com.tongweb.springboot.starter.TongWebServletWebServerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* 优雅停机配置
* 优雅停机配置 tomcat转换tongWeb
* matchIfMissing:当缺少shutdown.graceful.enable配置的时候是否加载该配置类true:缺少也加载false:默认的缺少配置不加载即不生效
*/
@Configuration
@ -15,10 +15,10 @@ import org.springframework.context.annotation.Configuration;
public class GracefulShutdownConfig {
@Bean
public ServletWebServerFactory servletContainer(GracefulShutdownTomcat gracefulShutdownTomcat) {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
tomcat.addConnectorCustomizers(gracefulShutdownTomcat);
return tomcat;
public ServletWebServerFactory servletContainer(GracefulShutdownTongWeb gracefulShutdownTongWeb) {
TongWebServletWebServerFactory tongWeb = new TongWebServletWebServerFactory();
tongWeb.addConnectorCustomizers(gracefulShutdownTongWeb);
return tongWeb;
}
}

19
code/smart-community/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/config/shutdown/GracefulShutdownTomcat.java → code/smart-community/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/config/shutdown/GracefulShutdownTongWeb.java

@ -1,28 +1,26 @@
package com.epmet.commons.tools.config.shutdown;
import org.apache.catalina.connector.Connector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.tongweb.container.connector.Connector;
import com.tongweb.springboot.starter.TongWebConnectorCustomizer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@Slf4j
@EnableConfigurationProperties(ShutdownProperties.class)
@Component
@ConditionalOnProperty(prefix = "shutdown.graceful", name = "enable", havingValue = "true", matchIfMissing = false)
public class GracefulShutdownTomcat implements TomcatConnectorCustomizer, ApplicationListener<ContextClosedEvent> {
public class GracefulShutdownTongWeb implements TongWebConnectorCustomizer, ApplicationListener<ContextClosedEvent> {
private static final Logger logger = LoggerFactory.getLogger(GracefulShutdownTomcat.class);
@Autowired
@Resource
private ShutdownProperties shutdownProperties;
private volatile Connector connector;
@ -31,6 +29,7 @@ public class GracefulShutdownTomcat implements TomcatConnectorCustomizer, Applic
public void customize(Connector connector) {
this.connector = connector;
}
@Override
public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
this.connector.pause();
@ -42,7 +41,7 @@ public class GracefulShutdownTomcat implements TomcatConnectorCustomizer, Applic
threadPoolExecutor.shutdown();
if (!threadPoolExecutor.awaitTermination(waitTimeSecs, TimeUnit.SECONDS)) {
String msg = String.format("Tomcat在【%s】秒内优雅停机失败,请手动处理", waitTimeSecs);
logger.error(msg);
log.error(msg);
}
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();

26
code/smart-community/epmet-gateway/src/main/java/com/epmet/GatewayApplication.java

@ -8,15 +8,9 @@
package com.epmet;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.tools.aspect.ServletExceptionHandler;
import com.epmet.commons.tools.config.RedissonConfig;
import com.epmet.commons.tools.config.ThreadDispatcherConfig;
import com.epmet.commons.tools.redis.RedisKeys;
import com.epmet.commons.tools.redis.RedisUtils;
import com.epmet.filter.CpProperty;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@ -24,9 +18,6 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import javax.annotation.PostConstruct;
import java.util.List;
/**
* 网关服务
*
@ -36,28 +27,11 @@ import java.util.List;
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
//@ServletComponentScan(basePackages = "com.epmet")
@ComponentScan(basePackages = {"com.epmet.*"}, excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {RedissonConfig.class, ThreadDispatcherConfig.class, ServletExceptionHandler.class}))
public class GatewayApplication {
@Autowired
private CpProperty cpProperty;
@Autowired
private RedisUtils redisUtils;
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args);
}
/**
* 初始化运营端校验资源列表
*/
// @PostConstruct
// public void initOperExamineResources() {
// if (!redisUtils.hasKey(RedisKeys.getOperExamineResourceUrls())) {
// List<CpProperty.OperExamineResource> operExamineResourceUrls = cpProperty.getOperExamineResourceUrls();
// redisUtils.setString(RedisKeys.getOperExamineResourceUrls(), JSON.toJSONString(operExamineResourceUrls));
// }
// }
}

Loading…
Cancel
Save