웹 개발

[spring] 생성자 혼동 피하기

노루아부지 2019. 8. 11. 12:52
   /*      생략     */
   public ConstructorConfusionDemo(String someValue)
   {
      System.out.println("string");
   }
   public ConstructorConfusionDemo(int someValue)
   {
      System.out.println("int");
   }
   /*        생략      */

위와같은 생성자가 있을때,

<bean id="constructorConfusion" class="경로">
   <constructor-arg value="1"/>
</bean>

이와 같은 코드를 작성하면 ConstructorConfusionDemo(String someValue) 생성자가 호출된다.

이 경우,    public ConstructorConfusionDemo(int someValue)생성자를 호출하고 싶다면 아래와 같이 type를 추가시켜주어야 한다.

<bean id="constructorConfusion" class="경로">
   <constructor-arg value="1" type="int"/>
</bean>
728x90
loading