코딩이 쉬워진다!/02. spring

spring 2일차

javajin 2018. 1. 17. 18:09
728x90
반응형
SMALL

#Spring framwork 2일차 2018-01-07#

spring08.maven


spring09.DI설정 -2

-src/main/jaava/Student.java

-src/main/jaava/StudenInfo.java

-src/main/resource/applicationContext.xml 

-src/main/java/TestMain.java

-생성자오버로딩 으로 처리 

 <constructor-arg>

 </constructor-arg>


spring10.interface 적용해보기 

- 자바 문법형태로 인터페이스를 구현해주고 applicationContext.xml에서 id 값을 매칭시켜주면 된다. 

- Pencil pencil= ctx.getBean("pencil",pencil.class);

  pencil.use();


spring11.xml설정파일이 여러개일 경우 처리방법 

- 설정된 xml파일을 GenericXMLApplicationContext(a,b,c)
  에 아규먼트로 ","를 활용하여 넣어준다.
- String path = "classpath:applicationContext.xml";
- String path1 = "classpath:applicationContext1.xml";
- AbstractApplicationContext ctx = new GenericXmlApplicationContext(path, path1);

spring12.applicationContext1.xml에서 xml c 와 p태그로 사용하는 방법 


1)applicationContext.xml에 아래내용을 추가한다. 

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

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


2)적용 c:는 생성자,p:는 프로퍼티

<bean id="family" class="com.nz.spring06.Family" 

c:papaName="아빠" c:mamiName="엄마" 

p:sisterName="누나" p:brotherName="홍브라더"> 



spring13.자바로 빈 설정하는 방법 

@configuration

@Bean

-이두개의 어노테이션으로 처리를 한다. 


spring14. 스프링 컨테이너의 라이프 사이클(lifecycle)

 

-스프링 컨테이너 생성

GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();

-스프링 컨테이너 설정

ctx.load("classpath:applicationContext.xml");

ctx.refresh();

-스프링 컨테이너 사용

Student student = ctx.getBean("student",Student.class);

System.out.println(student.getName());

System.out.println(student.getAge());

-스프링 컨테이너 종료

ctx.close();


spring15. 빈 생성, 소멸시 처리하기 위한 메소드 확인하기 

-1) class A implements InitializingBean, DisposableBean

@PostConstruct

public void initilTesting() {

System.out.println("initilTesting() 시작했습니다.");

}

@PreDestroy

public void dstroyTesting() {

System.out.println("dstroyTesting() 시작했습니다.");

}

-1) class A {

@PostConstruct

public void initTest(){}



@PreDestroy

publi void destroyTest(){}


}




728x90
반응형
LIST

'코딩이 쉬워진다! > 02. spring' 카테고리의 다른 글

spring 6일차  (2) 2018.01.23
spring 5일차  (2) 2018.01.22
spring 4일차  (2) 2018.01.19
spring 3일차  (0) 2018.01.19
spring 1일차  (0) 2018.01.17