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);
    }
}
相关推荐
linyb极客之路1 天前
告别 OpenFeign!Spring 6 原生 HttpExchange 微服务调用实战指南
spring boot·spring·spring cloud
小杨同学491 天前
C 语言实战:堆内存存储字符串 + 多种递归方案计算字符串长度
数据库·后端·算法
golang学习记1 天前
Go 中防止敏感数据意外泄露的几种姿势
后端
名字不好奇1 天前
C++虚函数表失效???
java·开发语言·c++
czlczl200209251 天前
Spring Boot 构建 SaaS 多租户架构
spring boot·后端·架构
小码编匠1 天前
完美替代 Navicat,一款开源免费、集成了 AIGC 能力的多数据库客户端工具!
数据库·后端·aigc
顺流1 天前
从零实现一个数据结构可视化调试器(一)
后端
u0104058361 天前
Java中的服务监控:Prometheus与Grafana的集成
java·grafana·prometheus
掘金者阿豪1 天前
Redis键值对批量删除全攻略:安全高效删除包含特定模式的键
后端
星浩AI1 天前
深入理解 LlamaIndex:RAG 框架核心概念与实践
人工智能·后端·python