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);
    }
}
相关推荐
xiaolyuh1231 天前
Spring MVC 深度解析
java·spring·mvc
-凌凌漆-1 天前
【java】java中函数加与不加abstract 的区别
java·开发语言
❀͜͡傀儡师1 天前
SpringBoot与Artemis整合,实现航空行李追踪消息中枢系统
java·spring boot·后端
青云交1 天前
Java 大视界 -- Java 大数据在智能交通高速公路收费系统优化与通行效率提升实战
java
qq_256247051 天前
AG-UI:让 AI 走出聊天框的“界面革命”
后端
哪里不会点哪里.1 天前
IoC(控制反转)详解:Spring 的核心思想
java·spring·rpc
麦兜*1 天前
SpringBoot Actuator监控端点详解,打造生产级应用健康检查
java·spring boot·后端
无限进步_1 天前
二叉搜索树(BST)详解:从原理到实现
开发语言·数据结构·c++·ide·后端·github·visual studio
悟能不能悟1 天前
Spring Boot 中处理跨域资源
java·spring boot·后端
qq_12498707531 天前
基于springboot+vue的无人机共享管理系统(源码+论文+部署+安装)
java·vue.js·spring boot·后端·毕业设计·无人机·计算机毕业设计