Announcement Announcement Module
Collapse
No announcement yet.
Problem with static factory method constructors Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with static factory method constructors

    I'm creating a javax.mail.session from the static getDefaultInstance method. the method is overloaded with 2 signatures, one with just a props, and a second with props and an authenticator. For some reason spring refuses to call just the one with a single props parameter.. here is my setup, ive tried specifiying index=0 etc, doesn't seem to help:

    Code:
      <bean name="javaMailSession" class="javax.mail.Session" factory-method="getDefaultInstance">
        <constructor-arg>
          <props>
            <prop key="mail.smtp.auth">true</prop>
            <prop key="mail.smtp.host"></prop>
            <prop key="mail.smtp.port"></prop>
            <prop key="mail.smtp.user"></prop>
            <prop key="mail.smtp.password"></prop>
          </props>
        </constructor-arg>
      </bean>
    Log file error:
    Code:
    2005-06-24 16&#58;00&#58;58,203 &#91;DEBUG&#93; support.DefaultListableBeanFactory - Ignoring factory method &#91;public static javax.mail.Session javax.mail.Session.getDefaultInstance&#40;java.util.Properties,javax.mail.Authenticator&#41;&#93; of bean 'javaMailSession'&#58; could not satisfy dependencies
    org.springframework.beans.factory.UnsatisfiedDependencyException&#58; Error creating bean with name 'javaMailSession' defined in ServletContext resource &#91;/WEB-INF/spring/tecas.xml&#93;&#58; Unsatisfied dependency expressed through constructor argument with index 1 of type &#91;javax.mail.Authenticator&#93;&#58; Ambiguous constructor argument types - did you specify the correct bean references as generic constructor arguments?
    Any ideas? Thanks!

  • #2
    hmm the factory-method seems to need some serious work on matching provided parameters with overloaded methods... had to resort to a much more vague way of doing what i needed:

    Code:
      <bean id="javaMailSession" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetClass"><value>javax.mail.Session</value></property>
        <property name="targetMethod"><value>getDefaultInstance</value></property>
        <property name="arguments">
          <list>
            <props>
              <prop key="mail.smtp.auth">true</prop>
              <prop key="mail.smtp.host"></prop>
              <prop key="mail.smtp.port"></prop>
              <prop key="mail.smtp.user"></prop>
              <prop key="mail.smtp.password"></prop>
            </props>
          </list>
        </property>
      </bean>

    Comment

    Working...
    X