springboot可配置开启自定义starter

可配置starter编写

1 引入依赖

xml 复制代码
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-autoconfigure</artifactId>
</dependency>

2 增加配置类

java 复制代码
@Configuration
public class NftServerStartConfiguration {

    @Bean
    @ConditionalOnProperty(prefix = "nft.server",name = "enabled", havingValue = "true")
    public void startBoot(){
        System.out.println("服务开启并启动了,欢迎使用ntfServer服务");
    }
}

3 编写注解配置

用import将第二步编写的配置类导入到注解中,让注解管理起来

java 复制代码
/**
 * nftserver注解开启
 * @author marlon
 * @create 2024-01-18 10:38
 */
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Import(value = NftServerStartConfiguration.class)
@Documented
@Inherited
public @interface NftServer {

}

业务使用可配置starter

1 引入starter配置

xml 复制代码
<dependency>
    <groupId>cn.com.agree.adfs</groupId>
    <artifactId>nft-server-sdk-starter</artifactId>
    <version>2.6.1</version>
</dependency>

2 配置文件配置参数

yaml 复制代码
nft:
  server:
    enabled: true

3 启动类上加注解@NftServer

java 复制代码
@SpringBootApplication
@NftServer
public class AdfsDemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(AdfsDemoApplication.class);
    }
}
相关推荐
lionliu051942 分钟前
WebAssembly (Wasm)
java·开发语言·wasm
咸鱼加辣1 小时前
【java面试题】springboot的生命周期
java·开发语言·spring boot
Billow_lamb1 小时前
MyBatis Plus 中常用的插件列表
java·mybatis
没逻辑1 小时前
gocron - 分布式定时任务管理系统
后端
程序猿DD1 小时前
人工智能如何改变 Anthropic 的工作方式
java·后端
C雨后彩虹1 小时前
任务总执行时长
java·数据结构·算法·华为·面试
桦说编程1 小时前
Guava Forwarding系列类详解——装饰器模式实战
java·后端·设计模式
柒.梧.2 小时前
数据结构:二叉排序树构建与遍历的解析与代码实现
java·开发语言·数据结构
VX:Fegn08952 小时前
计算机毕业设计|基于springboot + vue敬老院管理系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计