springboot:condition
程序员文章站
2022-06-16 08:09:48
...
public class LinuxCondition implements Condition{
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
return context.getEnvironment().getProperty("os.name").contains("Linux"); }
}
=============================================
public class MacCondition implements Condition{
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
return context.getEnvironment().getProperty("os.name").contains("Mac"); }
}
=============================================
public class WindowsCondition implements Condition{
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
return context.getEnvironment().getProperty("os.name").contains("Windows");
}
}
=============================================
@Configuration
public class MyConfiguration {
@Bean(name="emailerService")
@Conditional(WindowsCondition.class)
public Object windowsEmailerService(){
return new Object();
}
@Bean(name="emailerService")
@Conditional(LinuxCondition.class)
public Object linuxEmailerService(){
return new Object();
}
@Bean(name="emailerService")
@Conditional(MacCondition.class)
public Object macEmailerService(){
return new Object();
}
}
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
return context.getEnvironment().getProperty("os.name").contains("Linux"); }
}
=============================================
public class MacCondition implements Condition{
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
return context.getEnvironment().getProperty("os.name").contains("Mac"); }
}
=============================================
public class WindowsCondition implements Condition{
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
return context.getEnvironment().getProperty("os.name").contains("Windows");
}
}
=============================================
@Configuration
public class MyConfiguration {
@Bean(name="emailerService")
@Conditional(WindowsCondition.class)
public Object windowsEmailerService(){
return new Object();
}
@Bean(name="emailerService")
@Conditional(LinuxCondition.class)
public Object linuxEmailerService(){
return new Object();
}
@Bean(name="emailerService")
@Conditional(MacCondition.class)
public Object macEmailerService(){
return new Object();
}
}
上一篇: 爬取东方财富的利润表数据记录
下一篇: 一对多的通过中继的直接通信
推荐阅读
-
SpringBoot 监控管理模块actuator没有权限的问题解决方法
-
浅谈SpringBoot之事务处理机制
-
详解SpringBoot之集成Spring AOP
-
如何解决springboot读取配置文件的中文乱码问题
-
springboot使用hibernate validator校验方式
-
SpringBoot Admin 使用指南(推荐)
-
Springboot打成war包并在tomcat中运行的部署方法
-
springboot整合ehcache 实现支付超时限制的方法
-
Springboot打成war包并在tomcat中运行的部署方法
-
springboot 多模块将dao(mybatis)项目拆分出去