步骤一:

实现接口: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;
}
}

最新文章

  1. javase--反射
  2. Sql server2012连接Sql server 2008时出现的问题:已成功与服务器建立连接,但在登陆过程中发生错误。(provider:SSL Provider,error:0-接收到的消息异常,或格式不正确。)
  3. 【转】移动端viewport的使用
  4. MySQL Show命令的使用
  5. uml类关系
  6. UVA 1001 Say Cheese 奶酪里的老鼠(最短路,floyd)
  7. php获得当前日期时间 date函数
  8. ubuntu zend-eclipse-php debugger调试
  9. javascript必知必会之prototype
  10. oracle 插入含&字符串
  11. 自定义NavgationBa返回按钮
  12. CentOS7中安装MySQL5.7 (转)
  13. 笔记:Hibernate 数据库方言表
  14. 使用float属性的一些小技巧
  15. postgresql 删除库的时候报错database "temp_test_yang" is being accessed by other users
  16. docker文件复制到centos/linux/ubantun环境下
  17. 解决Everything1.4版本预览时不支持自定义后缀的问题
  18. Docket 使用命令
  19. 体验cygwin纪实
  20. (笔记)电路设计(十一)之DC/DC电源转换方案设计应用

热门文章

  1. Linux内核TCP MSS机制详细分析
  2. Vue 使用axios分片上传
  3. MySQL两地三中心方案初步设计【转】
  4. 人脸替换(FaceSwap)的一些思考
  5. Windows 10 Tensorflow 2 gpu正式版安装和更新日志
  6. 005 文档API
  7. layui日历控件设置选择日期不能超过当前日期
  8. rapidjson的简单使用(转)
  9. postgre ~模糊查询慢解决方式
  10. WebSocket始终保持连接的办法