- spring: 新增 @FastServiceScan 扫描注解与 FastServiceScanRegistrar / FastServiceScannerProcessor,支持扫描 FastBaseIService 和 FastBaseIServiceNew3518 两个基类、value/basePackages 别名、缺失基类跳过 - spring: ApplicationDestroyedRunner / ApplicationReadyEventListener / ApplicationStartedRunner / ContextClosedEventListener 迁移为 Kotlin,弃用注解补全 @Deprecated + ReplaceWith - build: 新增 VERSIONSTYPE 控制 RELEASES/SNAPSHOT 版本后缀,补充 Spring / MyBatis-Plus 测试依赖 - test: 新增 FastServiceScanRegistrarTest 5 个用例与 FastServiceScannerProcessorTest 2 个用例
This commit is contained in:
-83
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright 2026 mingliqiye
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile ApplicationDestroyedRunner.java
|
||||
* LastUpdate 2026-11-18 08:21:37
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
package com.mingliqiye.utils.springboot.annotation;
|
||||
|
||||
import org.springframework.context.event.ContextClosedEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 应用销毁(上下文关闭)事件监听注解。
|
||||
*
|
||||
* <p>标注在 Spring Bean 的方法上,当 Spring 应用上下文关闭
|
||||
* ({@link ContextClosedEvent} 发布)时自动调用该方法。</p>
|
||||
*
|
||||
* @deprecated 已弃用,请改用 {@link ContextClosedEventListener}(监听相同事件,命名更规范)。
|
||||
* @see ContextClosedEventListener
|
||||
* @see EventListener
|
||||
* @see ContextClosedEvent
|
||||
*/
|
||||
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@EventListener(ContextClosedEvent.class)
|
||||
@Order
|
||||
@Deprecated(since = "use ApplicationReadyEventListener")
|
||||
public @interface ApplicationDestroyedRunner {
|
||||
/**
|
||||
* SpEL 条件表达式,仅当表达式求值为 true 时才执行监听方法。
|
||||
*
|
||||
* @return 条件表达式,默认为空字符串(无条件执行)
|
||||
*/
|
||||
@AliasFor(annotation = EventListener.class, attribute = "condition")
|
||||
String condition() default "";
|
||||
|
||||
/**
|
||||
* 当事件不是 {@link ContextClosedEvent} 类型时是否仍默认执行监听方法。
|
||||
*
|
||||
* @return 是否默认执行,默认为 true
|
||||
*/
|
||||
@AliasFor(annotation = EventListener.class, attribute = "defaultExecution")
|
||||
boolean defaultExecution() default true;
|
||||
|
||||
/**
|
||||
* 监听器的唯一标识,用于注册可指定 id 的监听器。
|
||||
*
|
||||
* @return 监听器 id,默认为空字符串(自动生成)
|
||||
*/
|
||||
@AliasFor(annotation = EventListener.class, attribute = "id")
|
||||
String id() default "";
|
||||
|
||||
/**
|
||||
* 监听器的执行顺序,值越小优先级越高。
|
||||
*
|
||||
* @return 顺序值,默认为 {@link Ordered#LOWEST_PRECEDENCE}
|
||||
* @see Ordered#getOrder()
|
||||
*/
|
||||
@AliasFor(annotation = Order.class, attribute = "value")
|
||||
int order() default Ordered.LOWEST_PRECEDENCE;
|
||||
}
|
||||
-95
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright 2026 mingliqiye
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile ApplicationReadyEventListener.java
|
||||
* LastUpdate 2026-11-18 08:21:57
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
package com.mingliqiye.utils.springboot.annotation;
|
||||
|
||||
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
|
||||
/**
|
||||
* 应用就绪事件监听注解。
|
||||
*
|
||||
* <p>标注在 Spring Bean 的方法上,当 Spring Boot 应用完成启动并就绪
|
||||
* ({@link ApplicationReadyEvent} 发布)时自动调用该方法,
|
||||
* 等价于 {@code @EventListener(ApplicationReadyEvent.class)} 的组合简化写法。</p>
|
||||
*
|
||||
* <p>使用示例:</p>
|
||||
* <pre>{@code
|
||||
* @Component
|
||||
* public class InitTask {
|
||||
* @ApplicationReadyEventListener(order = 0)
|
||||
* public void onReady() {
|
||||
* // 应用就绪后执行的初始化逻辑
|
||||
* }
|
||||
* }
|
||||
* }</pre>
|
||||
*
|
||||
* @see EventListener
|
||||
* @see ApplicationReadyEvent
|
||||
*/
|
||||
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
@Order
|
||||
public @interface ApplicationReadyEventListener {
|
||||
/**
|
||||
* SpEL 条件表达式,仅当表达式求值为 true 时才执行监听方法。
|
||||
*
|
||||
* @return 条件表达式,默认为空字符串(无条件执行)
|
||||
*/
|
||||
@AliasFor(annotation = EventListener.class, attribute = "condition")
|
||||
String condition() default "";
|
||||
|
||||
/**
|
||||
* 当事件不是 {@link ApplicationReadyEvent} 类型时是否仍默认执行监听方法。
|
||||
*
|
||||
* @return 是否默认执行,默认为 true
|
||||
*/
|
||||
@AliasFor(annotation = EventListener.class, attribute = "defaultExecution")
|
||||
boolean defaultExecution() default true;
|
||||
|
||||
/**
|
||||
* 监听器的唯一标识,用于注册可指定 id 的监听器。
|
||||
*
|
||||
* @return 监听器 id,默认为空字符串(自动生成)
|
||||
*/
|
||||
@AliasFor(annotation = EventListener.class, attribute = "id")
|
||||
String id() default "";
|
||||
|
||||
|
||||
/**
|
||||
* 监听器的执行顺序,值越小优先级越高。
|
||||
*
|
||||
* @return 顺序值,默认为 {@link Ordered#LOWEST_PRECEDENCE}
|
||||
* @see Ordered#getOrder()
|
||||
*/
|
||||
@AliasFor(annotation = Order.class, attribute = "value")
|
||||
int order() default Ordered.LOWEST_PRECEDENCE;
|
||||
}
|
||||
-84
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
* Copyright 2026 mingliqiye
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile ApplicationStartedRunner.java
|
||||
* LastUpdate 2026-11-18 08:21:57
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
package com.mingliqiye.utils.springboot.annotation;
|
||||
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 应用启动完成事件监听注解。
|
||||
*
|
||||
* <p>标注在 Spring Bean 的方法上,当 Spring Boot 应用完成启动并就绪
|
||||
* ({@link ApplicationReadyEvent} 发布)时自动调用该方法。</p>
|
||||
*
|
||||
* @deprecated 已弃用,请改用 {@link ApplicationReadyEventListener}(功能完全一致,命名更规范)。
|
||||
* @see ApplicationReadyEventListener
|
||||
* @see EventListener
|
||||
* @see ApplicationReadyEvent
|
||||
*/
|
||||
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
@Order
|
||||
@Deprecated(since = "use ApplicationReadyEventListener")
|
||||
public @interface ApplicationStartedRunner {
|
||||
/**
|
||||
* SpEL 条件表达式,仅当表达式求值为 true 时才执行监听方法。
|
||||
*
|
||||
* @return 条件表达式,默认为空字符串(无条件执行)
|
||||
*/
|
||||
@AliasFor(annotation = EventListener.class, attribute = "condition")
|
||||
String condition() default "";
|
||||
|
||||
/**
|
||||
* 当事件不是 {@link ApplicationReadyEvent} 类型时是否仍默认执行监听方法。
|
||||
*
|
||||
* @return 是否默认执行,默认为 true
|
||||
*/
|
||||
@AliasFor(annotation = EventListener.class, attribute = "defaultExecution")
|
||||
boolean defaultExecution() default true;
|
||||
|
||||
/**
|
||||
* 监听器的唯一标识,用于注册可指定 id 的监听器。
|
||||
*
|
||||
* @return 监听器 id,默认为空字符串(自动生成)
|
||||
*/
|
||||
@AliasFor(annotation = EventListener.class, attribute = "id")
|
||||
String id() default "";
|
||||
|
||||
|
||||
/**
|
||||
* 监听器的执行顺序,值越小优先级越高。
|
||||
*
|
||||
* @return 顺序值,默认为 {@link Ordered#LOWEST_PRECEDENCE}
|
||||
* @see Ordered#getOrder()
|
||||
*/
|
||||
@AliasFor(annotation = Order.class, attribute = "value")
|
||||
int order() default Ordered.LOWEST_PRECEDENCE;
|
||||
}
|
||||
-93
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* Copyright 2026 mingliqiye
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile ContextClosedEventListener.java
|
||||
* LastUpdate 2026-11-18 08:21:23
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
package com.mingliqiye.utils.springboot.annotation;
|
||||
|
||||
import org.springframework.context.event.ContextClosedEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 应用上下文关闭事件监听注解。
|
||||
*
|
||||
* <p>标注在 Spring Bean 的方法上,当 Spring 应用上下文关闭
|
||||
* ({@link ContextClosedEvent} 发布)时自动调用该方法,
|
||||
* 等价于 {@code @EventListener(ContextClosedEvent.class)} 的组合简化写法,
|
||||
* 适用于应用停机前的资源清理、状态保存等场景。</p>
|
||||
*
|
||||
* <p>使用示例:</p>
|
||||
* <pre>{@code
|
||||
* @Component
|
||||
* public class CleanupTask {
|
||||
* @ContextClosedEventListener
|
||||
* public void onClosed() {
|
||||
* // 上下文关闭前执行的清理逻辑
|
||||
* }
|
||||
* }
|
||||
* }</pre>
|
||||
*
|
||||
* @see EventListener
|
||||
* @see ContextClosedEvent
|
||||
*/
|
||||
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@EventListener(ContextClosedEvent.class)
|
||||
@Order
|
||||
public @interface ContextClosedEventListener {
|
||||
/**
|
||||
* SpEL 条件表达式,仅当表达式求值为 true 时才执行监听方法。
|
||||
*
|
||||
* @return 条件表达式,默认为空字符串(无条件执行)
|
||||
*/
|
||||
@AliasFor(annotation = EventListener.class, attribute = "condition")
|
||||
String condition() default "";
|
||||
|
||||
/**
|
||||
* 当事件不是 {@link ContextClosedEvent} 类型时是否仍默认执行监听方法。
|
||||
*
|
||||
* @return 是否默认执行,默认为 true
|
||||
*/
|
||||
@AliasFor(annotation = EventListener.class, attribute = "defaultExecution")
|
||||
boolean defaultExecution() default true;
|
||||
|
||||
/**
|
||||
* 监听器的唯一标识,用于注册可指定 id 的监听器。
|
||||
*
|
||||
* @return 监听器 id,默认为空字符串(自动生成)
|
||||
*/
|
||||
@AliasFor(annotation = EventListener.class, attribute = "id")
|
||||
String id() default "";
|
||||
|
||||
/**
|
||||
* 监听器的执行顺序,值越小优先级越高。
|
||||
*
|
||||
* @return 顺序值,默认为 {@link Ordered#LOWEST_PRECEDENCE}
|
||||
* @see Ordered#getOrder()
|
||||
*/
|
||||
@AliasFor(annotation = Order.class, attribute = "value")
|
||||
int order() default Ordered.LOWEST_PRECEDENCE;
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright 2026 mingliqiye
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile FastServiceScan.java
|
||||
* LastUpdate 2026-11-23 14:44:48
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
package com.mingliqiye.utils.springboot.annotation;
|
||||
|
||||
import com.mingliqiye.utils.springboot.autoconfigure.FastServiceScanRegistrar;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 扫描继承自 {@code com.mingliqiye.utils.mybatisplus.FastBaseIService} 或
|
||||
* {@code com.mingliqiye.utils.mybatisplus.FastBaseIServiceNew3518} 的具体类并注册为 Spring Bean。
|
||||
* 两个基类分别对应旧版 {@code mybatis-plus-extension} 与新版 {@code mybatis-plus-spring},
|
||||
* 子类都会被扫描到;行为与 {@code @MapperScan} 类似:只有标注了本注解的启动类/配置类才会触发扫描。
|
||||
*
|
||||
* <p>扫描由 {@link FastServiceScanRegistrar} 注册的
|
||||
* {@code com.mingliqiye.utils.springboot.autoconfigure.FastServiceScannerProcessor} 完成,
|
||||
* 后者是 {@code BeanFactoryPostProcessor},会在所有 {@code BeanDefinitionRegistryPostProcessor}
|
||||
* (包括 {@code @MapperScan} 的 {@code MapperScannerConfigurer})之后执行,
|
||||
* 因此扫描注册时机在 mapper 之后,服务里的 {@code baseMapper} 可以正常注入。</p>
|
||||
*
|
||||
* <p>已经标注 {@code @Component} / {@code @Service} 的类会被跳过,交给普通组件扫描处理,避免重复注册。</p>
|
||||
*
|
||||
* <p>Java 用法:</p>
|
||||
* <pre>{@code
|
||||
* @SpringBootApplication
|
||||
* @MapperScan(basePackages = "com.example.mapper")
|
||||
* @FastServiceScan(basePackages = "com.example.service")
|
||||
* public class ExampleApplication {
|
||||
* }
|
||||
* }</pre>
|
||||
*
|
||||
* <p>Kotlin 用法:</p>
|
||||
* <pre>{@code
|
||||
* @SpringBootApplication
|
||||
* @MapperScan(basePackages = ["com.example.mapper"])
|
||||
* @FastServiceScan(basePackages = ["com.example.service"])
|
||||
* class ExampleApplication
|
||||
* }</pre>
|
||||
*
|
||||
* <p>不指定扫描包时,默认扫描标注类所在包。</p>
|
||||
* <p>{@code Kotlin} 请指定 {@code Service} 为 {@code open}</p>
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Import(FastServiceScanRegistrar.class)
|
||||
public @interface FastServiceScan {
|
||||
|
||||
/**
|
||||
* 要扫描的包,等价于 {@link #basePackages()}。
|
||||
*
|
||||
* @return 要扫描的包
|
||||
*/
|
||||
@AliasFor("basePackages")
|
||||
String[] value() default {};
|
||||
|
||||
/**
|
||||
* 要扫描的包。
|
||||
*
|
||||
* @return 要扫描的包
|
||||
*/
|
||||
|
||||
@AliasFor("value")
|
||||
String[] basePackages() default {};
|
||||
|
||||
/**
|
||||
* 以这些类所在包作为扫描包。
|
||||
*
|
||||
* @return 用于推导扫描包的类
|
||||
*/
|
||||
Class<?>[] basePackageClasses() default {};
|
||||
}
|
||||
Reference in New Issue
Block a user