refactor: 使用常量优化部分配置属性名

This commit is contained in:
2024-01-02 22:14:00 +08:00
parent 1f3687df6f
commit 20250681da
15 changed files with 109 additions and 15 deletions

View File

@@ -27,6 +27,7 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import top.charles7c.continew.starter.core.constant.PropertiesConstants;
import top.charles7c.continew.starter.core.constant.StringConstants;
/**
@@ -39,7 +40,7 @@ import top.charles7c.continew.starter.core.constant.StringConstants;
@Lazy
@AutoConfiguration
@ConditionalOnWebApplication
@ConditionalOnProperty(prefix = "continew-starter.cors", name = "enabled", havingValue = "true")
@ConditionalOnProperty(prefix = PropertiesConstants.CORS, name = PropertiesConstants.ENABLED, havingValue = "true")
@EnableConfigurationProperties(CorsProperties.class)
public class CorsAutoConfiguration {

View File

@@ -18,6 +18,7 @@ package top.charles7c.continew.starter.core.autoconfigure.cors;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import top.charles7c.continew.starter.core.constant.PropertiesConstants;
import top.charles7c.continew.starter.core.constant.StringConstants;
import java.util.ArrayList;
@@ -31,7 +32,7 @@ import java.util.List;
* @since 1.0.0
*/
@Data
@ConfigurationProperties(prefix = "continew-starter.cors")
@ConfigurationProperties(PropertiesConstants.CORS)
public class CorsProperties {
/**

View File

@@ -25,6 +25,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import top.charles7c.continew.starter.core.constant.PropertiesConstants;
import top.charles7c.continew.starter.core.exception.BaseException;
import java.util.Arrays;
@@ -42,7 +43,7 @@ import java.util.concurrent.ScheduledExecutorService;
@Lazy
@AutoConfiguration
@RequiredArgsConstructor
@ConditionalOnProperty(prefix = "continew-starter.thread-pool", name = "enabled", havingValue = "true")
@ConditionalOnProperty(prefix = PropertiesConstants.THREAD_POOL, name = PropertiesConstants.ENABLED, havingValue = "true")
@EnableAsync(proxyTargetClass = true)
public class AsyncAutoConfiguration implements AsyncConfigurer {

View File

@@ -26,6 +26,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import top.charles7c.continew.starter.core.constant.PropertiesConstants;
import top.charles7c.continew.starter.core.util.ExceptionUtils;
import java.util.concurrent.ScheduledExecutorService;
@@ -42,7 +43,7 @@ import java.util.concurrent.ThreadPoolExecutor;
@Slf4j
@Lazy
@AutoConfiguration
@ConditionalOnProperty(prefix = "continew-starter.thread-pool", name = "enabled", havingValue = "true")
@ConditionalOnProperty(prefix = PropertiesConstants.THREAD_POOL, name = PropertiesConstants.ENABLED, havingValue = "true")
@EnableConfigurationProperties(ThreadPoolProperties.class)
public class ThreadPoolAutoConfiguration {

View File

@@ -18,6 +18,7 @@ package top.charles7c.continew.starter.core.autoconfigure.threadpool;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import top.charles7c.continew.starter.core.constant.PropertiesConstants;
/**
* 线程池配置属性
@@ -27,7 +28,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
* @since 1.0.0
*/
@Data
@ConfigurationProperties(prefix = "continew-starter.thread-pool")
@ConfigurationProperties(PropertiesConstants.THREAD_POOL)
public class ThreadPoolProperties {
/**

View File

@@ -0,0 +1,80 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.charles7c.continew.starter.core.constant;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
/**
* 配置属性相关常量
*
* @author Charles7c
* @since 1.1.1
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class PropertiesConstants {
/**
* ContiNew Starter
*/
public static final String CONTINEW_STARTER = "continew-starter";
/**
* 启用配置
*/
public static final String ENABLED = "enabled";
/**
* 跨域配置
*/
public static final String CORS = CONTINEW_STARTER + ".cors";
/**
* 线程池配置
*/
public static final String THREAD_POOL = CONTINEW_STARTER + ".thread-pool";
/**
* 日志配置
*/
public static final String LOG = CONTINEW_STARTER + ".log";
/**
* 存储配置
*/
public static final String STORAGE = CONTINEW_STARTER + ".storage";
/**
* 本地存储配置
*/
public static final String STORAGE_LOCAL = STORAGE + ".local";
/**
* 验证码配置
*/
public static final String CAPTCHA = CONTINEW_STARTER + ".captcha";
/**
* 图形验证码配置
*/
public static final String CAPTCHA_GRAPHIC = CAPTCHA + ".graphic";
/**
* 行为验证码配置
*/
public static final String CAPTCHA_BEHAVIOR = CAPTCHA + ".behavior";
}