생성자 객체 질문

19.08.15 18:00 작성 조회수 46

0

삭제된 글입니다

답변 4

·

답변을 작성해보세요.

0

<?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/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="bean1" class="board.test2"/>
    
    <bean id="bean2" class="board.test2_1">
    	<constructor-arg ref="bean1"></constructor-arg>
    </bean>
</beans>

0

package board;

public class test2_1 {
	
	test2 t2;
	
	public test2_1(test2 t2) {
		this.t2 = t2;
	}
	
	public void a() {
		System.out.println("test"+t2.a);
	}
}

0

public class test2 {
	int a=100;
}

0

import org.springframework.context.support.*;

public class test {

	public static void main(String[] args) {
		
		GenericXmlApplicationContext ctx = new GenericXmlApplicationContext("classpath:applicationContext.xml");
		test2_1 t = ctx.getBean("bean2", test2_1.class);
		t.a();
		
		ctx.close();
	}

}