Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.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
如何使用spring中另一个类中定义的参数从静态方法初始化bean_Spring_Parameters_Factory - Fatal编程技术网

如何使用spring中另一个类中定义的参数从静态方法初始化bean

如何使用spring中另一个类中定义的参数从静态方法初始化bean,spring,parameters,factory,Spring,Parameters,Factory,我想创建一个新的DateTimeFormatter作为bean,并将其交给另一个bean 这就是我在代码中所做的 DateTimeFormatter formatter=DateTimeFormat.forPattern(“blah”) 但如何在春季初始化格式化程序 以下是我从这些有用的回答中得到的灵感 <bean id="dateFormatter" class="org.joda.time.format.DateTimeFormat" factory-method="forPatter

我想创建一个新的DateTimeFormatter作为bean,并将其交给另一个bean

这就是我在代码中所做的

DateTimeFormatter formatter=DateTimeFormat.forPattern(“blah”)

但如何在春季初始化格式化程序

以下是我从这些有用的回答中得到的灵感

<bean id="dateFormatter" class="org.joda.time.format.DateTimeFormat" factory-method="forPattern">
  <constructor-arg value="blah"/>
</bean>

我已经有一段时间没有使用Spring了,但下面是:

DateTimeFormatter
不是从接口扩展而来的(我只找到了对Joda接口的引用),因此任何使用它的东西都必须准确地引用类型。这意味着您不会从依赖项注入中获得任何好处(因为使用格式化程序的内容与格式化程序的确切类型紧密耦合)。那么你真的想这么做吗


假设您这样做了,看看第4.3.2.2节和其他章节,它提供了创建bean的所有方法。您可以通过静态方法创建格式化程序,然后将其传递给使用它的构造函数(构造函数注入,第4.4.1.1节)

我已经有一段时间没有使用Spring了,但下面是:

DateTimeFormatter
不是从接口扩展而来的(我只找到了对Joda接口的引用),因此任何使用它的东西都必须准确地引用类型。这意味着您不会从依赖项注入中获得任何好处(因为使用格式化程序的内容与格式化程序的确切类型紧密耦合)。那么你真的想这么做吗

假设您这样做了,看看第4.3.2.2节和其他章节,它提供了创建bean的所有方法。您可以通过静态方法创建格式化程序,然后将其传递给使用它的构造函数(构造函数注入,第4.4.1.1节)