Results 1 to 4 of 4

Thread: factory-method fails ??

  1. #1
    Join Date
    Feb 2012
    Posts
    8

    Default 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. #2
    Join Date
    Sep 2010
    Location
    Cork, Ireland
    Posts
    16

    Default

    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"

  3. #3
    Join Date
    Feb 2012
    Posts
    8

    Default

    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 !

  4. #4
    Join Date
    Feb 2007
    Posts
    5

    Default

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

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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •