spring 条件化配置
2024-08-27 01:39:14
步骤一:
实现接口:org.springframework.context.annotation.Condition
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata; public class MyJdbcTc implements Condition {
@Override
public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
try {
//你需要加载的类权限的名称,或者指定的某些条件
conditionContext.getClassLoader().loadClass("java.lang.Object");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
} 步骤二:
再Bean方法或者类上使用org.springframework.context.annotation.Conditional注解
@Configuration
public class MyConfig {
@Bean
@Conditional(MyJdbcTc.class)
public User user(){
User user = new User();
user.setId(1);
user.setName("hello");
return user;
}
}
最新文章
- javase--反射
- Sql server2012连接Sql server 2008时出现的问题:已成功与服务器建立连接,但在登陆过程中发生错误。(provider:SSL Provider,error:0-接收到的消息异常,或格式不正确。)
- 【转】移动端viewport的使用
- MySQL Show命令的使用
- uml类关系
- UVA 1001 Say Cheese 奶酪里的老鼠(最短路,floyd)
- php获得当前日期时间 date函数
- ubuntu zend-eclipse-php debugger调试
- javascript必知必会之prototype
- oracle 插入含&;字符串
- 自定义NavgationBa返回按钮
- CentOS7中安装MySQL5.7 (转)
- 笔记:Hibernate 数据库方言表
- 使用float属性的一些小技巧
- postgresql 删除库的时候报错database ";temp_test_yang"; is being accessed by other users
- docker文件复制到centos/linux/ubantun环境下
- 解决Everything1.4版本预览时不支持自定义后缀的问题
- Docket 使用命令
- 体验cygwin纪实
- (笔记)电路设计(十一)之DC/DC电源转换方案设计应用