Closed. This question needs details or clarity。它当前不接受答案。












想改善这个问题吗?添加详细信息,并通过editing this post来解决问题。

7年前关闭。



Improve this question




经过调查代码,我发现:
 <bean id="TestBean" class="com.test.checkDate"
 factory-method="getPreviousDate">
 <constructor-arg value .............

 ...............................

怎么可能呢?
谢谢。

最佳答案

来自文档


<bean id="exampleBean" class="examples.ExampleBean"
      factory-method="createInstance">
  <constructor-arg ref="anotherExampleBean"/>
  <constructor-arg ref="yetAnotherBean"/>
  <constructor-arg value="1"/>
</bean>

<bean id="anotherExampleBean" class="examples.AnotherBean"/>
<bean id="yetAnotherBean" class="examples.YetAnotherBean"/>
public class ExampleBean {

    // a private constructor
    private ExampleBean(...) {
      ...
    }

    // a static factory method; the arguments to this method can be
    // considered the dependencies of the bean that is returned,
    // regardless of how those arguments are actually used.
    public static ExampleBean createInstance (
            AnotherBean anotherBean, YetAnotherBean yetAnotherBean, int i) {

        ExampleBean eb = new ExampleBean (...);
        // some other operations...
            return eb;
    }
}

关于java - 没有工厂的 Spring Bean 怎么能有工厂的方法呢?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7952548/

10-09 06:07