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);
    }
}
相关推荐
百***812717 分钟前
【SpringBoot】SpringBoot中分页插件(PageHelper)的使用
java·spring boot·后端
百***864618 分钟前
SpringBoot中自定义Starter
java·spring boot·后端
q***071418 分钟前
VScode 开发 Springboot 程序
java·spring boot·后端
q***465219 分钟前
Spring中使用Async进行异步功能开发实战-以大文件上传为例
java·后端·spring
q***385121 分钟前
SpringCloud实战【九】 SpringCloud服务间调用
java·spring boot·spring cloud
岚天start21 分钟前
K8S环境中Containerd运行时占用文件定位清理
java·rpc·kubernetes
2501_9167665426 分钟前
解决idea依赖导入不成功的问题
java·intellij-idea
头发还在的女程序员29 分钟前
基于JAVA语言的短剧小程序-抖音短剧小程序
java·开发语言·小程序
vir0238 分钟前
P12155 [蓝桥杯 2025 省 Java B] 消失的蓝宝
java·职场和发展·蓝桥杯
Codebee1 小时前
Qoder CLI 与 OneCode 平台深度整合技术实践:CLI委托驱动的开发范式革新
后端