spring常用语法

etl表达式解析

if (rawValue != null && rawValue.startsWith("#{") && entryValue.endsWith("}")) {

// assume it's spel

StandardEvaluationContext context = new StandardEvaluationContext();

context.setBeanResolver(new BeanFactoryResolver(beanFactory));

Expression expression = parser.parseExpression(entryValue,

new TemplateParserContext());

value = expression.getValue(context);

}

属性绑定
复制代码
Bindable<T> bindable = Bindable.of(this.configurable.getConfigClass());T t =new Binder(propertySources, null, conversionService)
      .bindOrCreate(configurationPropertyName, bindable, handler);

ApplicationContext context = SpringApplication.run(Application.class, args);

Binder binder = Binder.get(context.getEnvironment());

绑定简单配置

FooProperties foo = binder.bind("com.didispace", Bindable.of(FooProperties.class)).get();

System.out.println(foo.getFoo());

绑定List配置

List<String> post = binder.bind("com.didispace.post", Bindable.listOf(String.class)).get();

System.out.println(post);

List<PostInfo> posts=binder.bind("com.didispace.posts",Bindable.listOf(PostInfo.class)).get();

System.out.println(posts);

// 读取配置 System.out.println(context.getEnvironment().containsProperty("com.didispace.database-platform"));

System.out.println(context.getEnvironment().containsProperty("com.didispace.databasePlatform"));

配置绑定到Map对象
复制代码
Map<String, DsConfig> dsMap = binder.bind("demo.dynamic", Bindable.mapOf(String.class, DsConfig.class)).get();
System.out.println("Map Config: " + dsMap);
配置转换处理
复制代码
String decPwd = binder.bind("demo.enc.pwd", Bindable.of(String.class))
        .map(s -> new String(Base64Utils.decodeFromString(s))).get();
System.out.println("解码之后的数据是: " + decPwd);
注册绑定过程回调

String dec = binder.bindOrCreate("demo.enc.pwd", Bindable.of(String.class), new BindHandler() {

@Override

public <T> Bindable<T> onStart(ConfigurationPropertyName name, Bindable<T> target, BindContext context) {

System.out.println("开始绑定: " + name);

return BindHandler.super.onStart(name, target, context);

}

@Override

public Object onSuccess(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result) {

System.out.println("绑定成功!" + name + " val:" + target.getValue() + " res: " + result);

return new String(Base64Utils.decodeFromString((String) result));

}

@Override

public Object onCreate(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result) {

System.out.println("创建: " + name + " val:" + target.getValue() + " res: " + result);

return BindHandler.super.onCreate(name, target, context, result);

}

@Override

public Object onFailure(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Exception error) throws Exception {

System.out.println("绑定失败! " + name + " " + error.getMessage());

return BindHandler.super.onFailure(name, target, context, error);

}

@Override

public void onFinish(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result) throws Exception {

System.out.println("绑定结束: " + name + " val:" + target.getValue() + " res: " + result);

BindHandler.super.onFinish(name, target, context, result);

}

});

System.out.println("绑定回调: " + dec);

相关推荐
方见华Richard1 天前
AGI安全三大方向机构对比清单(2025-2026)
人工智能·经验分享·交互·原型模式·空间计算
sg_knight1 天前
原型模式(Prototype)
python·设计模式·开发·原型模式
方见华Richard2 天前
递归对抗引擎RAE:AGI终极希望与内生安全范式革新,自指认知AI为碳硅共生必然主体
人工智能·交互·学习方法·原型模式·空间计算
方见华Richard2 天前
全球AGI实验室梯队标准清单(2026)
人工智能·经验分享·交互·原型模式·空间计算
方见华Richard2 天前
世毫九实验室RAE递归对抗引擎:技术与原理全解
人工智能·经验分享·交互·原型模式·空间计算
方见华Richard2 天前
递归对抗引擎RAE:世毫九重构AGI底层逻辑的终极范式与全维度价值极致解读
人工智能·交互·学习方法·原型模式·空间计算
方见华Richard3 天前
世毫九:思维是意义空间的几何运动的详细推导过程
人工智能·交互·学习方法·原型模式·空间计算
方见华Richard3 天前
世毫九认知几何学公式推导过程(严格数学构造)
人工智能·交互·学习方法·原型模式·空间计算
方见华Richard3 天前
《认知几何学:思维如何弯曲意义空间》补充材料
人工智能·经验分享·交互·原型模式·空间计算
方见华Richard5 天前
整数阶时间重参数化:基于自适应豪斯多夫维数的偏微分方程正则化新框架
人工智能·笔记·交互·原型模式·空间计算