Results 1 to 3 of 3

Thread: Strange behavior in constructor injection.

  1. #1
    Join Date
    Sep 2004
    Location
    Recife - Pernambuco - Brazil
    Posts
    7

    Default 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
    Marcos Silva Pereira
    Recife - Pernambuco - Brazil

  2. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    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
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3
    Join Date
    Sep 2004
    Location
    Recife - Pernambuco - Brazil
    Posts
    7

    Default

    Quote 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.
    Quote 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
    Marcos Silva Pereira
    Recife - Pernambuco - Brazil

Similar Threads

  1. really strange problem with session
    By a_wronski in forum Security
    Replies: 2
    Last Post: Jun 24th, 2005, 10:23 PM
  2. Strange setup bean behaviour with validation
    By Christian in forum Web Flow
    Replies: 4
    Last Post: Jun 20th, 2005, 05:27 PM
  3. Replies: 1
    Last Post: Apr 29th, 2005, 06:56 AM
  4. Replies: 3
    Last Post: Jan 31st, 2005, 08:52 AM
  5. Replies: 0
    Last Post: Jan 3rd, 2005, 03:31 AM

Posting Permissions

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