add export config
This commit is contained in:
@@ -29,21 +29,12 @@ public class CORSConfig {
|
||||
/** 允许跨域的地址 */
|
||||
private String[] allowOrigin;
|
||||
|
||||
/** 是否允许请求带有验证信息 */
|
||||
private boolean allowCredentials;
|
||||
|
||||
/** 允许请求的方法 */
|
||||
private String allowMethods;
|
||||
|
||||
/** 允许服务端访问的客户端请求头 */
|
||||
private String allowHeaders;
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean<Filter> corsFilter() {
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
config.addAllowedHeader(allowHeaders);
|
||||
config.addAllowedMethod(allowMethods);
|
||||
config.setAllowCredentials(allowCredentials);
|
||||
config.addAllowedHeader("*");
|
||||
config.addAllowedMethod("*");
|
||||
config.setAllowCredentials(true);
|
||||
config.setAllowedOriginPatterns(Arrays.asList(allowOrigin));
|
||||
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
package com.imyeyu.api.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.imyeyu.api.modules.blog.entity.ArticleRanking;
|
||||
import com.imyeyu.api.modules.common.entity.Multilingual;
|
||||
import com.imyeyu.spring.bean.RedisConfigParams;
|
||||
import com.imyeyu.spring.config.AbstractRedisConfig;
|
||||
import com.imyeyu.spring.util.Redis;
|
||||
import com.imyeyu.spring.util.RedisSerializers;
|
||||
import com.imyeyu.utils.Time;
|
||||
import io.lettuce.core.api.StatefulConnection;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
@@ -33,9 +36,12 @@ import java.time.Duration;
|
||||
@Configuration
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@EnableAutoConfiguration
|
||||
@RequiredArgsConstructor
|
||||
@ConfigurationProperties(prefix = "spring.redis")
|
||||
public class RedisConfig extends AbstractRedisConfig {
|
||||
|
||||
private final ObjectMapper jackson;
|
||||
|
||||
// ---------- 连接配置 ----------
|
||||
|
||||
/** 地址 */
|
||||
@@ -47,50 +53,9 @@ public class RedisConfig extends AbstractRedisConfig {
|
||||
/** 密码 */
|
||||
private String password;
|
||||
|
||||
/** 超时(毫秒) */
|
||||
private int timeout;
|
||||
|
||||
/** 连接池 */
|
||||
private Lettuce lettuce;
|
||||
|
||||
/** 数据库 */
|
||||
private Database database;
|
||||
|
||||
/**
|
||||
* 连接池
|
||||
*
|
||||
* @author 夜雨
|
||||
* @since 2023-08-21 16:23
|
||||
*/
|
||||
@Data
|
||||
public static class Lettuce {
|
||||
|
||||
/** 配置 */
|
||||
private Pool pool;
|
||||
|
||||
/**
|
||||
* 配置
|
||||
*
|
||||
* @author 夜雨
|
||||
* @since 2023-08-21 16:23
|
||||
*/
|
||||
@Data
|
||||
public static class Pool {
|
||||
|
||||
/** 最大活跃连接 */
|
||||
private int maxActive;
|
||||
|
||||
/** 最小空闲连接 */
|
||||
private int minIdle;
|
||||
|
||||
/** 最大空闲连接 */
|
||||
private int maxIdle;
|
||||
|
||||
/** 最大等待时间(秒) */
|
||||
private int maxWait;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据库
|
||||
*
|
||||
@@ -146,10 +111,10 @@ public class RedisConfig extends AbstractRedisConfig {
|
||||
setHost(host);
|
||||
setPort(port);
|
||||
setPassword(password);
|
||||
setTimeout(timeout);
|
||||
setMaxActive(lettuce.pool.maxActive);
|
||||
setMinIdle(lettuce.pool.minIdle);
|
||||
setMaxIdle(lettuce.pool.maxIdle);
|
||||
setTimeout(Time.SI * 8);
|
||||
setMaxActive(8);
|
||||
setMinIdle(1);
|
||||
setMaxIdle(8);
|
||||
}};
|
||||
}
|
||||
|
||||
@@ -226,7 +191,7 @@ public class RedisConfig extends AbstractRedisConfig {
|
||||
/** @return 文章访问统计,文章 ID: {@link ArticleRanking}(JSON) */
|
||||
@Bean("redisArticleRanking")
|
||||
public Redis<Long, ArticleRanking> getArticleRankingRedisTemplate() {
|
||||
return getRedis(database.articleRanking, RedisSerializers.LONG, RedisSerializers.jacksonSerializer(ArticleRanking.class));
|
||||
return getRedis(database.articleRanking, RedisSerializers.LONG, RedisSerializers.jacksonSerializer(jackson, ArticleRanking.class));
|
||||
}
|
||||
|
||||
/** @return 文章访问记录,IP: [文章 ID] */
|
||||
|
||||
@@ -2,8 +2,6 @@ package com.imyeyu.api.config;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
@@ -19,37 +17,17 @@ import java.util.concurrent.ThreadPoolExecutor;
|
||||
@Data
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@ConfigurationProperties(prefix = "spring.async.thread-pool")
|
||||
public class ThreadPoolConfig {
|
||||
|
||||
/** 核心数量 */
|
||||
private int corePoolSize;
|
||||
|
||||
/** 最大数量 */
|
||||
private int maxPoolSize;
|
||||
|
||||
/** 等待区容量 */
|
||||
private int queueCapacity;
|
||||
|
||||
/** 最大保持活跃时间(秒) */
|
||||
private int keepAliveSeconds;
|
||||
|
||||
/** 最大等待时间(秒) */
|
||||
private int awaitTerminationSeconds;
|
||||
|
||||
/** 线程名称前缀 */
|
||||
private String threadNamePrefix;
|
||||
|
||||
@Bean(name = "threadPoolTaskExecutor")
|
||||
public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setCorePoolSize(corePoolSize);
|
||||
executor.setMaxPoolSize(maxPoolSize);
|
||||
executor.setQueueCapacity(queueCapacity);
|
||||
executor.setKeepAliveSeconds(keepAliveSeconds);
|
||||
executor.setAwaitTerminationSeconds(awaitTerminationSeconds);
|
||||
executor.setThreadNamePrefix(threadNamePrefix);
|
||||
executor.setCorePoolSize(16);
|
||||
executor.setMaxPoolSize(32);
|
||||
executor.setQueueCapacity(16);
|
||||
executor.setKeepAliveSeconds(60);
|
||||
executor.setAwaitTerminationSeconds(60);
|
||||
executor.setThreadNamePrefix("thread-pool-task-executor-");
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
executor.initialize();
|
||||
return executor;
|
||||
|
||||
@@ -70,8 +70,8 @@ public class GiteaDBConfig {
|
||||
ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
|
||||
List<String> mapperLocations = new ArrayList<>();
|
||||
mapperLocations.add("classpath:mapper/gitea/**/*.xml");
|
||||
for (int i = 0; i < mapperLocations.size(); i++) {
|
||||
resources.addAll(List.of(resourceResolver.getResources(mapperLocations.get(i))));
|
||||
for (String mapperLocation : mapperLocations) {
|
||||
resources.addAll(List.of(resourceResolver.getResources(mapperLocation)));
|
||||
}
|
||||
}
|
||||
String[] typeAliases = {
|
||||
|
||||
@@ -83,8 +83,8 @@ public class TimiServerDBConfig {
|
||||
mapperLocations.add("classpath:mapper/system/**/*.xml");
|
||||
mapperLocations.add("classpath:mapper/journal/**/*.xml");
|
||||
mapperLocations.add("classpath:mapper/minecraft/**/*.xml");
|
||||
for (int i = 0; i < mapperLocations.size(); i++) {
|
||||
resources.addAll(List.of(resourceResolver.getResources(mapperLocations.get(i))));
|
||||
for (String mapperLocation : mapperLocations) {
|
||||
resources.addAll(List.of(resourceResolver.getResources(mapperLocation)));
|
||||
}
|
||||
}
|
||||
String[] typeAliases = {
|
||||
|
||||
Reference in New Issue
Block a user