웹 & 프레임워크

Spring 생성자를 통한 의존성 주입

늘근이 2014. 6. 27. 14:22

생성된 후에 setter호출?

생성만들때 받는거?

 

필수인애들은 생성자를 만들어서 고고싱한다 setter는 지우고 생성자를 만드러라

 

위에껀 번거롭게 하는거고, 3.1부터 추가된버전  c namespace를 이용하는 좀 간단한 방법임!

 

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                  xmlns:c="http://www.springframework.org/schema/c"

                  xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.2.xsd">

 

<!-- <bean id="greeting" class="com.gorakgarak.sample2.constructor.GreetingServiceImpl">

                  <constructor-arg index="0">

                                   <ref bean ="outputter"/>

                  </constructor-arg>

</bean>

 

<bean id="outputter" class="com.gorakgarak.sample2.constructor.OutputServiceImplFile">

                  <constructor-arg index="0">

                                   <value>log.txt</value>

                  </constructor-arg>

</bean> -->

 

<bean id="greeting" class="com.gorakgarak.sample2.constructor.GreetingServiceImpl"

c:outputter-ref="outputter">

</bean>

 

 

 

<!-- //밑에거랑 같음

<bean id="outputter" class="com.gorakgarak.sample2.constructor.OutputServiceImplFile"

c:fileName="log.txt" >

</bean>  -->

<bean id="outputter" class="com.gorakgarak.sample2.constructor.OutputServiceImplFile"

c:_0="log.txt" >

</bean>

 

 

</beans>