Announcement Announcement Module
Collapse
No announcement yet.
Strange behavior in constructor injection. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Strange behavior in constructor injection.

    Hi, I have the following bean in my application context:
    Code:
    <bean id="lucenePath" class="java.io.File">
    	<constructor-arg index="0">
    		<value>C&#58;/Tomcat/pc2/WEB-INF/lucene-index</value>
    	</constructor-arg>
    </bean>
    If I remove the parameter "index" in constructor-arg tag, Spring try inject dependency file path in constructor File(String, String), not in File(String). My question is: why it tries this if there is only a constructor argument?

    I'm using Spring 1.1.3 and read context xml with ClassPathXmlApplicationContext class.

    Best regards

  • #2
    Spring tries to find out what constructor to use when your class (File) has more than one constructor. You need to give Spring more informations to help it use the correct constructor.
    Also, did you consider using Spring build-in Resource support?
    HTH

    Comment


    • #3
      Originally posted by irbouho
      Spring tries to find out what constructor to use when your class (File) has more than one constructor. You need to give Spring more informations to help it use the correct constructor.
      Hi, Omar , thanks for you answer. But, if I'm setting only a parameter, Spring must not to try use two parameters constructor, must it? I think that, in this case, Spring should be skillful to find the rigth constructor. Course, if I have other one parameter constructor with other parameter type, I really need to give more information to it.
      Originally posted by irbouho
      Also, did you consider using Spring build-in Resource support?HTH
      Hum, I will read about this in documentation. Thanks by tip.

      Best Regards

      Comment

      Working...
      X