SpringBoot3升级 (#1947)
Some checks failed
supersonic CentOS CI / build (21) (push) Has been cancelled
supersonic mac CI / build (21) (push) Has been cancelled
supersonic ubuntu CI / build (21) (push) Has been cancelled
supersonic windows CI / build (21) (push) Has been cancelled

This commit is contained in:
mislayming
2024-12-11 17:09:20 +08:00
committed by GitHub
parent f6622319a4
commit 07f6be51c7
91 changed files with 246 additions and 253 deletions

View File

@@ -12,8 +12,8 @@
<artifactId>launchers-common</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
</properties>
<dependencies>
@@ -46,4 +46,4 @@
</dependencies>
</project>
</project>

View File

@@ -1,8 +1,10 @@
package com.tencent.supersonic.config;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.LaxRedirectStrategy;
import org.apache.hc.client5.http.impl.LaxRedirectStrategy;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
@@ -16,14 +18,19 @@ public class RestTemplateConfig {
@Bean
public RestTemplate restTemplate() {
// HttpClient 5 较新版本才会有LaxRedirectStrategy, 所以我重新定义了
CloseableHttpClient httpClient =
// HttpClientBuilder.create().setRedirectStrategy(new DefaultRedirectStrategy()) //
// 使用宽松重定向策略
HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()) // 使用宽松重定向策略
.build();
HttpComponentsClientHttpRequestFactory httpRequestFactory =
new HttpComponentsClientHttpRequestFactory();
new HttpComponentsClientHttpRequestFactory(httpClient);
httpRequestFactory.setConnectionRequestTimeout(2000);
httpRequestFactory.setConnectTimeout(10000);
httpRequestFactory.setReadTimeout(7200000);
HttpClient httpClient =
HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
httpRequestFactory.setHttpClient(httpClient);
RestTemplate restTemplate = new RestTemplate(httpRequestFactory);
restTemplate.getMessageConverters().set(1,
new StringHttpMessageConverter(StandardCharsets.UTF_8));

View File

@@ -1,18 +1,43 @@
package com.tencent.supersonic.web;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.ErrorPageRegistrar;
import org.springframework.boot.web.server.ErrorPageRegistry;
import org.springframework.core.Ordered;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.resource.NoResourceFoundException;
import org.springframework.web.servlet.resource.ResourceHttpRequestHandler;
/** error page config */
@Component
public class ErrorPageConfig implements ErrorPageRegistrar {
public class ErrorPageConfig implements ErrorPageRegistrar, HandlerExceptionResolver, Ordered {
@Override
public void registerErrorPages(ErrorPageRegistry registry) {
ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/webapp/index.html");
registry.addErrorPages(error404Page);
}
@Override
public int getOrder() {
return Ordered.HIGHEST_PRECEDENCE;
}
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response,
Object handler, Exception ex) {
if (handler instanceof ResourceHttpRequestHandler
&& ex instanceof NoResourceFoundException) {
ModelAndView modelAndView = new ModelAndView("/webapp/index.html");
response.setStatus(HttpStatus.OK.value());
return modelAndView;
}
return null;
}
}

View File

@@ -3,18 +3,20 @@ package com.tencent.supersonic.web;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/webapp/**").addResourceLocations("classpath:/webapp/");
registry.addResourceHandler("/favicon.ico").addResourceLocations("classpath:/webapp/");
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("forward:webapp/index.html");
registry.addViewController("/").setViewName("forward:/webapp/index.html");
}
}