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. 32
      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. * Copyright (c) 2018 人人开源 All rights reserved.
* * <p>
* https://www.renren.io * 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; package com.epmet.commons.tools.config.shutdown;
import com.tongweb.springboot.starter.TongWebServletWebServerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 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.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
/** /**
* 优雅停机配置 * 优雅停机配置 tomcat转换tongWeb
* matchIfMissing:当缺少shutdown.graceful.enable配置的时候是否加载该配置类true:缺少也加载false:默认的缺少配置不加载即不生效 * matchIfMissing:当缺少shutdown.graceful.enable配置的时候是否加载该配置类true:缺少也加载false:默认的缺少配置不加载即不生效
*/ */
@Configuration @Configuration
@ -15,10 +15,10 @@ import org.springframework.context.annotation.Configuration;
public class GracefulShutdownConfig { public class GracefulShutdownConfig {
@Bean @Bean
public ServletWebServerFactory servletContainer(GracefulShutdownTomcat gracefulShutdownTomcat) { public ServletWebServerFactory servletContainer(GracefulShutdownTongWeb gracefulShutdownTongWeb) {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory(); TongWebServletWebServerFactory tongWeb = new TongWebServletWebServerFactory();
tomcat.addConnectorCustomizers(gracefulShutdownTomcat); tongWeb.addConnectorCustomizers(gracefulShutdownTongWeb);
return tomcat; 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; package com.epmet.commons.tools.config.shutdown;
import org.apache.catalina.connector.Connector; import com.tongweb.container.connector.Connector;
import org.slf4j.Logger; import com.tongweb.springboot.starter.TongWebConnectorCustomizer;
import org.slf4j.LoggerFactory; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent; import org.springframework.context.event.ContextClosedEvent;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@Slf4j
@EnableConfigurationProperties(ShutdownProperties.class) @EnableConfigurationProperties(ShutdownProperties.class)
@Component @Component
@ConditionalOnProperty(prefix = "shutdown.graceful", name = "enable", havingValue = "true", matchIfMissing = false) @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); @Resource
@Autowired
private ShutdownProperties shutdownProperties; private ShutdownProperties shutdownProperties;
private volatile Connector connector; private volatile Connector connector;
@ -31,6 +29,7 @@ public class GracefulShutdownTomcat implements TomcatConnectorCustomizer, Applic
public void customize(Connector connector) { public void customize(Connector connector) {
this.connector = connector; this.connector = connector;
} }
@Override @Override
public void onApplicationEvent(ContextClosedEvent contextClosedEvent) { public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
this.connector.pause(); this.connector.pause();
@ -42,7 +41,7 @@ public class GracefulShutdownTomcat implements TomcatConnectorCustomizer, Applic
threadPoolExecutor.shutdown(); threadPoolExecutor.shutdown();
if (!threadPoolExecutor.awaitTermination(waitTimeSecs, TimeUnit.SECONDS)) { if (!threadPoolExecutor.awaitTermination(waitTimeSecs, TimeUnit.SECONDS)) {
String msg = String.format("Tomcat在【%s】秒内优雅停机失败,请手动处理", waitTimeSecs); String msg = String.format("Tomcat在【%s】秒内优雅停机失败,请手动处理", waitTimeSecs);
logger.error(msg); log.error(msg);
} }
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();

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

@ -8,15 +8,9 @@
package com.epmet; package com.epmet;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.tools.aspect.ServletExceptionHandler; import com.epmet.commons.tools.aspect.ServletExceptionHandler;
import com.epmet.commons.tools.config.RedissonConfig; import com.epmet.commons.tools.config.RedissonConfig;
import com.epmet.commons.tools.config.ThreadDispatcherConfig; 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.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 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.ComponentScan;
import org.springframework.context.annotation.FilterType; import org.springframework.context.annotation.FilterType;
import javax.annotation.PostConstruct;
import java.util.List;
/** /**
* 网关服务 * 网关服务
* *
@ -36,28 +27,11 @@ import java.util.List;
@SpringBootApplication @SpringBootApplication
@EnableDiscoveryClient @EnableDiscoveryClient
@EnableFeignClients @EnableFeignClients
//@ServletComponentScan(basePackages = "com.epmet")
@ComponentScan(basePackages = {"com.epmet.*"}, excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {RedissonConfig.class, ThreadDispatcherConfig.class, ServletExceptionHandler.class})) @ComponentScan(basePackages = {"com.epmet.*"}, excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {RedissonConfig.class, ThreadDispatcherConfig.class, ServletExceptionHandler.class}))
public class GatewayApplication { public class GatewayApplication {
@Autowired public static void main(String[] args) {
private CpProperty cpProperty; SpringApplication.run(GatewayApplication.class, args);
}
@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