Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 是否可以使用Spring为API present类提供值_Java_Spring_Swing - Fatal编程技术网

Java 是否可以使用Spring为API present类提供值

Java 是否可以使用Spring为API present类提供值,java,spring,swing,Java,Spring,Swing,是否还有其他方法可以使用Spring向API(而不是类的成员)提供参数? 我知道我可以将一个API调用的结果传递给类的成员 <bean id="registryService" class="foo.MyRegistry"> ...properties set etc... </bean> <bean id="MyClient" class="foo.MyClient"> <property name="endPoint" value="#{reg

是否还有其他方法可以使用Spring向API(而不是类的成员)提供参数?
我知道我可以将一个API调用的结果传递给类的成员

<bean id="registryService" class="foo.MyRegistry">
...properties set etc...
</bean>

<bean id="MyClient" class="foo.MyClient">
  <property name="endPoint" value="#{registryService.getEndPoint('bar')}"/>
</bean>

…属性集等。。。

但是,我想把这个值传递给API(基本上我是在spring的JButton上添加
ActionListener

不是真正的spring专家,而是。。。 在春天3

@Value("#{properties.getAppropriateActionListener()}")
public void setActionListener(ActionListener listener) {
   myJButton.setActionListener(listener); 
}

另外,我认为Spring希望setEndpoint()和getEndPoint()方法能够解析名为“endPoint”的属性。声明这样的属性可以有效地将值传递给setEndPoint()方法。因此,将值传递给API(我假设它正在调用方法调用)实际上非常简单。

为什么需要这个?你在春天宣布了JButton?您可以在上下文中声明ActionListener实现,并从上下文中获取以在JButton中注册。@Vitaly:实际上我想使代码通用化。目前我正在添加JButton的一个面板上,将来我可能会更改为JComboBox、JcheckBox等。我不想使用硬编码ActionListner的代码。我想要的是,当我获得JButton实例时,ActionListner的实例应该从springSetter获得attach,而不需要getter,这足以让Spring配置bean。因为根据JavaBean规范,这将是一个只写属性。@Nikola Kolev:“endPoint”只是一个例子。在我知道的事情之后,我问了我的问题。我想将ActionListener设置为已经定义了addActionListener API的JButton。我想把参数传递给它。