mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-09-09 08:57:17 +08:00
feat(extension/crud): 新增启用注解,便于灵活控制启用/关闭 CRUD REST API、全局异常处理器增强
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.extension.crud.annotation;
|
||||
|
||||
import org.springframework.context.annotation.Import;
|
||||
import top.charles7c.continew.starter.extension.crud.autoconfigure.CrudRestControllerAutoConfiguration;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* CRUD REST Controller 启用注解
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 1.2.0
|
||||
*/
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Import({CrudRestControllerAutoConfiguration.class})
|
||||
public @interface EnableCrudRestController {
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.extension.crud.annotation;
|
||||
|
||||
import org.springframework.context.annotation.Import;
|
||||
import top.charles7c.continew.starter.extension.crud.autoconfigure.GlobalExceptionHandlerAutoConfiguration;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 全局异常、错误处理器启用注解
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 1.2.0
|
||||
*/
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Import({GlobalExceptionHandlerAutoConfiguration.class})
|
||||
public @interface EnableGlobalExceptionHandler {
|
||||
}
|
@@ -19,8 +19,8 @@ package top.charles7c.continew.starter.extension.crud.autoconfigure;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.format.support.FormattingConversionService;
|
||||
import org.springframework.web.accept.ContentNegotiationManager;
|
||||
@@ -30,14 +30,14 @@ import org.springframework.web.servlet.resource.ResourceUrlProvider;
|
||||
import top.charles7c.continew.starter.extension.crud.handler.CrudRequestMappingHandlerMapping;
|
||||
|
||||
/**
|
||||
* CRUD 自动配置
|
||||
* CRUD REST Controller 自动配置
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Slf4j
|
||||
@AutoConfiguration
|
||||
public class CrudAutoConfiguration extends DelegatingWebMvcConfiguration {
|
||||
@Configuration
|
||||
public class CrudRestControllerAutoConfiguration extends DelegatingWebMvcConfiguration {
|
||||
|
||||
/**
|
||||
* CRUD 请求映射器处理器映射器(覆盖默认 RequestMappingHandlerMapping)
|
||||
@@ -58,6 +58,6 @@ public class CrudAutoConfiguration extends DelegatingWebMvcConfiguration {
|
||||
|
||||
@PostConstruct
|
||||
public void postConstruct() {
|
||||
log.debug("[ContiNew Starter] - Auto Configuration 'Extension-CRUD' completed initialization.");
|
||||
log.debug("[ContiNew Starter] - Auto Configuration 'Extension-CRUD REST Controller' completed initialization.");
|
||||
}
|
||||
}
|
@@ -16,11 +16,11 @@
|
||||
|
||||
package top.charles7c.continew.starter.extension.crud.autoconfigure;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import top.charles7c.continew.starter.extension.crud.handler.GlobalErrorHandler;
|
||||
import top.charles7c.continew.starter.extension.crud.handler.GlobalExceptionHandler;
|
||||
@@ -32,9 +32,13 @@ import top.charles7c.continew.starter.extension.crud.handler.GlobalExceptionHand
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Slf4j
|
||||
@AutoConfiguration
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@Import({GlobalExceptionHandler.class, GlobalErrorHandler.class})
|
||||
@ConditionalOnMissingBean(BasicErrorController.class)
|
||||
@ComponentScan("top.charles7c.continew.starter.extension.crud.handler")
|
||||
public class GlobalExceptionHandlerAutoConfiguration {
|
||||
|
||||
@PostConstruct
|
||||
public void postConstruct() {
|
||||
log.debug("[ContiNew Starter] - Auto Configuration 'Extension-Global Exception Handler' completed " + "initialization.");
|
||||
}
|
||||
}
|
||||
|
@@ -1,2 +0,0 @@
|
||||
top.charles7c.continew.starter.extension.crud.autoconfigure.CrudAutoConfiguration
|
||||
top.charles7c.continew.starter.extension.crud.autoconfigure.GlobalExceptionHandlerAutoConfiguration
|
Reference in New Issue
Block a user