关于类对象getter的@Conditionalonexpression [英] @Conditionalonexpression on a class object getter

查看:132
本文介绍了关于类对象getter的@Conditionalonexpression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有办法在运行时通过评估在运行时获取其值的类的对象来使用@conditionalonexpression启用类。

I was wondering if there is a way to enable a class using @conditionalonexpression during runtime by evaluating an object of a class which gets its value at runtime.

FOr例如:

@ConditionalOnExpression(#{propertyobject.getexenabled()})
class ex1{

}

propertyobject实例在运行时填充值(在程序开头说)
这可能实现吗?

propertyobject instance is filled with value at runtime(Say at the beginning of the program) Is this possible to be achieved?

推荐答案

是的,它可能是 getexenabled( )方法应该是静态的。

Yes, it is possible but getexenabled() method should be static.

喜欢:

@SpringBootApplication
public class So44456388Application {

    public static void main(String[] args) {
        SpringApplication.run(So44456388Application.class, args);
    }

    public static class Evaluator {
        public static boolean getexenabled() {
            //your logic here
            return true /*false*/;
        }
    }

    @Component
    @ConditionalOnExpression("#{T(com.stackoverflow.so44456388.So44456388Application$Evaluator).getexenabled()}")
    public static class RichBean {
        @PostConstruct
        private void init() {
            System.out.println("RichBean");
        }
    }
}

这篇关于关于类对象getter的@Conditionalonexpression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆