---
title: "Spring配置Bean的问题"
author: "jiangchuhan"
date: "2011-06-20T10:35:00Z"
tags: []
slug: "spring-bean"
draft: false
lastmod: "2014-02-16T13:23:36Z"
id: 2017707
url: "https://jiangchuhan.iteye.com/blog/2017707"
---

今天发现了construtor-arg和property的一点不同之处，详述如下。(Spring版本2.5.6)

对于int类型的属性：

property的value可以指定某个类的public static变量，而construtor-arg的value则不能。

比如：

这个是没有问题的

&lt;bean id="transport"  
class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean"&gt;  
&lt;property name="staticField"&gt;  
&lt;value&gt;com.ibm.mq.jms.JMSC.MQJMS\_TP\_CLIENT\_MQ\_TCPIP&lt;/value&gt;  
&lt;/property&gt;  
&lt;/bean&gt;

而这个则会报错

&lt;bean id="a" class="com.chjiang.A" init-method="init"&gt;  
&lt;constructor-arg type="int" index="0"&gt;

&lt;value&gt;com.chjiang.B.STATIC\_VARIABLE&lt;/value&gt;

&lt;/constructor-arg&gt;  
&lt;/bean&gt;

需要改成这样才可以

&lt;bean id="a" class="com.chjiang.A" init-method="init"&gt;

&lt;constructor-arg type="int" index="0" value="0"&gt;  
&lt;/bean&gt;