밀김 2023. 6. 1. 15:07
728x90

 

 

 

 

 

 

 

 

 

 

- 모델 : view단에서 꽂아넣을 데이터

 

 

 

 

 

 

 

 

 

- DI : 디펜던시 인젝션 (부품결합)

 

 

- 기업형은 코드를 나눌때 '레이어'로 나눈다

 

 

- 결합하는 능력까지 갖고있는 컨테이너 IOC

 

 

역방향이라는것은 곧 조립형 이라는 뜻이다

 

 

 

 

 

xml 지시서

 

 

 

 

 

- classpath : xml과 같은 위치에 있을때

 

- fileSystem: 운영체제의 절대경로에서 읽어들이려 할때

 

- xmlWeb : xml이 웹에 있을때

 

-  annotationconfig : 자바코드와 같은 위치에 있을때

 

 

 

- 클래스 패스

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
      https://www.springframework.org/schema/beans/spring-beans.xsd">

   <bean id="..." class="...">
      <!-- collaborators and configuration for this bean go here -->
   </bean>

   <bean id="..." class="...">
      <!-- collaborators and configuration for this bean go here -->
   </bean>

   <!-- more bean definitions go here -->

</beans>

 

 

 

 

package kr.co.rland.web.di;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import kr.co.rland.web.entity.Menu;

public class Program {

	public static void main(String[] args) {
		
		ApplicationContext context 
		      = new ClassPathXmlApplicationContext("res/config.xml"); 
		Menu menu = (Menu) context.getBean("menu");
		System.out.println(menu);
		

	}

}

 

 

 <bean id="ui" class="kr.co.rland.web.di.DecoConsoleUI"/>
 //콩자루에 콩담아서
 ConsoleUI ui = (DecoConsoleUI)context.getBean("ui");
 //콩 꺼내기

 

 

- 조립은 스프링이 해준다

 

 

<property name="menu" ref="m"/>
//이 한구문이 setter injection이다
//첫번째 menu는 setmenu
//프로퍼티 : 속성값 주입

ref는 다른 bean을 사용하기 위해서 적어준것

 

 

 

 

 

<beans xmlns="http://www.springframework.org/schema/beans"
	   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
      https://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/context
      https://www.springframework.org/schema/context/spring-context.xsd">
   <context:
   
   //이 과정을 해주면
   
   <!--<property name="menu" ref="m"/>-->
   //xml에서 귀찮게 수정하는 이런짓 안해도 되고 어노테이션만 붙일수 있게 해줌!!!!!!!!!!!!~

 

 

 

 

xsd : 태그를 정의하는 내용을 담고있는 파일

 

 

 

알아서 찾아서 오토매틱하게 세터를 인젝션 해라

 

 

 

얘를 내 콩자루에 잇는 구성요소로 담아줘! 하는 어노테이션 Component

 

<context:annotation-config/> : 얘는 콩자루에 담겨진 다음에 실행할수 있는 애임

 

<context:component-scan base-package="kr.co.rland.web"/> : 콩자루에 있는 경로들..타고타고 들어가면서 찾는거

이거 붙여주면 <context:annotation-config/> 생략해도 된다

 

 

@Component("ui") : 이름을 이렇게 옆에 적어줄수도 있다

 

 

- @Autowired는 필드에 붙이는게 좋다 

 

 

 

 

 

 

 

- Autowired 붙이는거 디폴트는 필드에 하는게 바람직하다. 근데 세터에하든 필드에하든 각각의 장단점이 있다

뭔가 세팅될때 해야될일이 있으면 세터에 붙인다

 

 

 

 

여러가지 컴포넌트인데 의미부여만 조금씩 다른것뿐

 

 

 

 

- 마이바티스는 쿼리만 알려주면 알아서 다 만들어줌

 

 

마이바티스 가져와야되는것들

 

 

 

 

 

 

 

 

 

 

 

728x90