Spring bean initialization with multiple-arg method

前端 未结 2 2092
滥情空心
滥情空心 2020-12-15 19:08

I would like to create the following Spring bean (a JMX monitor) which has a method setThresholds(Number highThreshold,Number lowThreshold).

Could I invo

2条回答
  •  生来不讨喜
    2020-12-15 19:40

    I've never seen this done. The big idea of Spring is that you create and initialise straight forward beans. Therefore the only methods that will be called are therefore single argument Setters(...) and Constructors. The definition of what's supported will be in the following schema:

    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

    Your way around this problem is to get your bean to implement InitializingBean and call your method in the void afterPropertiesSet() method:

    eg:

    public void setHighThreadHold(Number highThreshHold) {}
    
    public void setLowThreashHold(Number lowThreadHold) {}
    
    
    public void afterPropertiesSet() {
        setThresholds(highThreshold,lowThreshold);
    }
    

提交回复
热议问题