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);
    }
}
相关推荐
寻星探路4 小时前
【深度长文】万字攻克网络原理:从 HTTP 报文解构到 HTTPS 终极加密逻辑
java·开发语言·网络·python·http·ai·https
想用offer打牌5 小时前
MCP (Model Context Protocol) 技术理解 - 第二篇
后端·aigc·mcp
曹牧6 小时前
Spring Boot:如何测试Java Controller中的POST请求?
java·开发语言
KYGALYX6 小时前
服务异步通信
开发语言·后端·微服务·ruby
掘了6 小时前
「2025 年终总结」在所有失去的人中,我最怀念我自己
前端·后端·年终总结
爬山算法7 小时前
Hibernate(90)如何在故障注入测试中使用Hibernate?
java·后端·hibernate
kfyty7257 小时前
集成 spring-ai 2.x 实践中遇到的一些问题及解决方案
java·人工智能·spring-ai
猫头虎7 小时前
如何排查并解决项目启动时报错Error encountered while processing: java.io.IOException: closed 的问题
java·开发语言·jvm·spring boot·python·开源·maven
李少兄7 小时前
在 IntelliJ IDEA 中修改 Git 远程仓库地址
java·git·intellij-idea