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);
    }
}
相关推荐
风象南3 小时前
很多人说,AI 让技术平权了,小白也能乱杀老师傅 ?
人工智能·后端
雨中飘荡的记忆5 小时前
ElasticJob分布式调度从入门到实战
java·后端
Se7en2585 小时前
推理平台全景
后端
大漠_w3cpluscom5 小时前
你学不会 CSS,不是笨,是方向错了
后端
cipher8 小时前
ERC-4626 通胀攻击:DeFi 金库的"捐款陷阱"
前端·后端·安全
毅航9 小时前
自然语言处理发展史:从规则、统计到深度学习
人工智能·后端
JxWang059 小时前
Task04:字符串
后端
树獭叔叔10 小时前
10-让模型更小更聪明,学而不忘:知识蒸馏与持续学习
后端·aigc·openai
JxWang0510 小时前
Task02:链表
后端