可配置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);
}
}