Announcement Announcement Module
Collapse
No announcement yet.
factory-method fails ?? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • factory-method fails ??

    Greetings,

    Although I read http://static.springsource.org/sprin...tory-lifecycle

    I fail to understand why this fails :

    <bean id="foo" factory-bean="exe" factory-method="newCachedThreadPool"/>
    <bean id="exe" class="java.util.concurrent.Executors"/>

    I thought that Executors.newCachedThreadPool would return me a ThreadPoolExecutor that could be referenced as foo.

    But STS tells me Non-static factory method 'newCachedThreadPool' not found in factory bean class.

    I Use JSE 6 and knows there is s the mistake is elsewhere.

    Can someone please explain to me what's wrong ?

    thanks !

  • #2
    why don't you use directly:
    <bean id="foo" class="java.util.concurrent.Executors" factory-method="newCachedThreadPool" />

    In the documentation you are referring to there's in section 3.2.3.2.2 statement:
    "Note that the definition does not specify the type (class) of the returned object, only the class containing the factory method"

    Comment


    • #3
      You were right, your proposal didn't work (I had tried it before) because the setter was not respecting javabeans convention.

      Now it works.

      Thank you !

      Comment


      • #4
        Use following [ only for static factory method as per doc ]

        <bean id="foo" class="java.util.concurrent.Executors" factory-method="newCachedThreadPool" />

        Comment

        Working...
        X