spring boot 3.06

This commit is contained in:
Jesse-Ma
2023-05-25 09:35:17 +08:00
parent c7d135cc15
commit 668a022a07
16 changed files with 232 additions and 222 deletions

17
pom.xml
View File

@@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.5</version>
<version>3.0.6</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.flagnote</groupId>
@@ -20,7 +20,8 @@
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.compilerVersion>17</maven.compiler.compilerVersion>
<spring-cloud.version>2022.0.2</spring-cloud.version>
<docker.image.prefix>flagnote</docker.image.prefix>
<docker.repostory>registry.openif.com:5000</docker.repostory>
<docker.registry.name>flagnote</docker.registry.name>
</properties>
<dependencies>
<dependency>
@@ -56,7 +57,7 @@
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.22</version>
<version>5.8.18</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -117,11 +118,15 @@
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.2.2</version>
<configuration>
<googleContainerRegistryEnabled>false</googleContainerRegistryEnabled>
<dockerHost>http://rancher:42375</dockerHost>
<serverId>docker-openif</serverId>
<registryUrl>http://${docker.repository}</registryUrl>
<pushImage>true</pushImage>
<dockerHost>http://144.34.221.20:42375</dockerHost>
<imageName>
${docker.image.prefix}/${project.artifactId}:${project.version}</imageName>
${docker.repostory}/${docker.registry.name}/${project.artifactId}:${project.version}
</imageName>
<dockerDirectory>src/main/docker</dockerDirectory>
<resources>
<resource>

View File

@@ -5,8 +5,6 @@ import java.util.concurrent.ThreadLocalRandom;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.DefaultResponse;
@@ -16,7 +14,6 @@ import org.springframework.cloud.client.loadbalancer.RequestData;
import org.springframework.cloud.client.loadbalancer.RequestDataContext;
import org.springframework.cloud.client.loadbalancer.Response;
import org.springframework.cloud.loadbalancer.core.NoopServiceInstanceListSupplier;
import org.springframework.cloud.loadbalancer.core.RandomLoadBalancer;
import org.springframework.cloud.loadbalancer.core.ReactorServiceInstanceLoadBalancer;
import org.springframework.cloud.loadbalancer.core.SelectedInstanceCallback;
import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;

View File

@@ -10,8 +10,10 @@ import org.springframework.core.env.Environment;
//@Configuration 必须注释掉
public class BkrLoadBalancerConfiguration {
@Bean
public ReactorLoadBalancer<ServiceInstance> reactorServiceInstanceLoadBalancer(Environment environment, LoadBalancerClientFactory loadBalancerClientFactory) {
public ReactorLoadBalancer<ServiceInstance> reactorServiceInstanceLoadBalancer(Environment environment,
LoadBalancerClientFactory loadBalancerClientFactory) {
String name = environment.getProperty(LoadBalancerClientFactory.PROPERTY_NAME);
return new BizKeyLoadBalancerClient(loadBalancerClientFactory.getLazyProvider(name, ServiceInstanceListSupplier.class), name);
return new BizKeyLoadBalancerClient(
loadBalancerClientFactory.getLazyProvider(name, ServiceInstanceListSupplier.class), name);
}
}

View File

@@ -1,7 +1,5 @@
package com.flagnote.gateway.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
@@ -29,8 +27,7 @@ public class GwCorsFilter {
config.addAllowedMethod("DELETE");
config.addAllowedMethod("PATCH");
UrlBasedCorsConfigurationSource source =
new UrlBasedCorsConfigurationSource(new PathPatternParser());
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
source.registerCorsConfiguration("/**", config);
return new CorsWebFilter(source);

View File

@@ -12,7 +12,6 @@ import org.springframework.web.server.ServerWebExchange;
import com.flagnote.gateway.utils.BizKeyUtils;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import reactor.core.publisher.Mono;
@@ -41,7 +40,6 @@ public class ValidateNoteCipherFilter implements GatewayFilter, Ordered {
return exchange.getResponse().setComplete();
}
return chain.filter(exchange);
}

View File

@@ -8,7 +8,6 @@ import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.support.ServerWebExchangeUtils;
import org.springframework.core.Ordered;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
@@ -33,7 +32,8 @@ public class ValidateNoteKeyFilter implements GatewayFilter, Ordered {
if (!BizKeyUtils.validateKey(noteKey)) {
NoteMeta meta = new NoteMeta();
DataBuffer dataBuffer = exchange.getResponse().bufferFactory().wrap(JsonUtils.toJson(meta).getBytes(StandardCharsets.UTF_8));
DataBuffer dataBuffer = exchange.getResponse().bufferFactory()
.wrap(JsonUtils.toJson(meta).getBytes(StandardCharsets.UTF_8));
return exchange.getResponse().writeWith(Flux.just(dataBuffer));
}

View File

@@ -1,22 +1,13 @@
package com.flagnote.gateway.filter.factory;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory.NameConfig;
import org.springframework.cloud.gateway.support.GatewayToStringStyler;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import com.flagnote.gateway.filter.ValidateNoteCipherFilter;
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Mono;
@Slf4j
@Component
@@ -26,7 +17,6 @@ public class ValidateNoteCipherGatewayFilterFactory
@Autowired
private ValidateNoteCipherFilter validateNoteCipherFilter;
public ValidateNoteCipherGatewayFilterFactory() {
super(NameConfig.class);
}

View File

@@ -1,22 +1,13 @@
package com.flagnote.gateway.filter.factory;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory.NameConfig;
import org.springframework.cloud.gateway.support.GatewayToStringStyler;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import com.flagnote.gateway.filter.ValidateNoteKeyFilter;
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Mono;
@Slf4j
@Component
@@ -26,7 +17,6 @@ public class ValidateNoteKeyGatewayFilterFactory
@Autowired
private ValidateNoteKeyFilter validateNoteKeyFilter;
public ValidateNoteKeyGatewayFilterFactory() {
super(NameConfig.class);
}

View File

@@ -92,7 +92,6 @@ public class BizKeyUtils {
return md5(key + "#" + MIX_STRING + "#" + initTime).equals(cipher);
}
public static String getSecretKey(String key, String password) {
return md5(key + md5(MIX_STRING + password));
}

View File

@@ -79,12 +79,9 @@ public class JsonUtils {
return parse(json, null, type);
}
/**
* json => 对象处理方法
* <br>
* 参数clazz和type必须一个为null另一个不为null
* <br>
* json => 对象处理方法 <br>
* 参数clazz和type必须一个为null另一个不为null <br>
* 此方法不对外暴露访问权限为private
*
* @param json 源json串

View File

@@ -5,7 +5,8 @@ import java.io.Serializable;
import lombok.Data;
@Data
public class NoteMeta implements Serializable {/**
public class NoteMeta implements Serializable {
/**
*
*/
private static final long serialVersionUID = -8234044213813670440L;

View File

@@ -5,7 +5,6 @@ spring:
config:
name: flagnote-gateway
profile: prd
uri: http://flagnote-config-01:8080/flagnote-config,http://flagnote-config-02:8080/flagnote-config
uri: http://flagnote-config-01:8080/flagnote-config
config:
import: optional:configserver:http://flagnote-config-01:8080/,optional:configserver:http://flagnote-config-02:8080/
import: optional:configserver:http://flagnote-config-01:8080/

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<springProperty scope="context" name="logPath" source="logback.logPath"/>
<property name="pattern" value="[%date{yyyy-MM-dd HH:mm:ss.SSS}] %X{logthreadId} %-5level %logger{80} %method %line - %msg%n"/>
<property name="charsetEncoding" value="UTF-8"/>
<property name="LOG_HOME" value="${logPath}"/>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${pattern}</pattern>
<charset>${charsetEncoding}</charset>
</encoder>
</appender>
<appender name="infoLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
<append>true</append>
<encoder>
<pattern>${pattern}</pattern>
<charset>${charsetEncoding}</charset>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>
${LOG_HOME}${file.separator}%d{yyMMdd}_info_%i.log
</fileNamePattern>
<maxHistory>30</maxHistory>
<maxFileSize>20MB</maxFileSize>
</rollingPolicy>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
</appender>
<root level="INFO">
<appender-ref ref="console"/>
<appender-ref ref="infoLog"/>
</root>
</configuration>