gpt4 book ai didi

java - 如何使用 XML 配置文件配置 Spring 4 中提供的条件 bean

转载 作者:太空宇宙 更新时间:2023-11-04 12:19:15 25 4
gpt4 key购买 nike

我想使用 XMl Spring 配置而不是通过注释来配置下面示例中所示的条件 bean。是否可以通过XML配置来实现条件bean?

public class TestCondition1 implements Condition
{
@Override
public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata)
{
return context.getEnvironment().getProperty("os.name").contains("Windows");
}
}

@Configuration
public class BeanTestConfiguration
{
@Bean(name="TesService")
@Conditional(TestCondition1.class)
public BeanTestConditionService getTestService()
{
return new BeanTestConditionService();
}
}

public class BeanTestConditionService
{
public BeanTestConditionService()
{
System.out.println("I am in test setvice");
}
}

最佳答案

Not supported yet ,并且可能暂时不会

Eventually closing this as Won't Fix since the whole condition model has really been designed with annotations in mind, and is generally a better fit there. If any common needs remain for XML configuration, we'd rather fine-tune the declarative profile model which is already available in XML.

关于java - 如何使用 XML 配置文件配置 Spring 4 中提供的条件 bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39032184/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com