-- DI
Dependency 의존 : 하나의 클래스에서 기능이 수행될 때, 다른 클래스나 컴포넌트를 사용(의존)함을 의미
Injection 주입 : 하나의 클래스에서 다른 클래스나 컴포넌트를 사용할 수 있도록 설정함 (Spring은 컨테이너가 의존주입 함.)
-- 사용하기
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
프로젝트 우클릭 -> properties -> build path -> add -> resources
resources에 spring-context.xml 넣어놓기
spring framework maven repository -> Spring Context
버전 맞게 pom.xml에 넣어주기
Maven Dependencies에 jar 파일 들어간 거 확인 가능
Dependency Hierarchy에서 확인 가능
resources -> spring-context.xml에 <bean>, <property> 추가
아래 코드 --> Spring의 bean 객체를 생성하는 포맷임.
EmpServiceImpl empService = new EmpServiceImpl();
empService.setDAO(dao); 와 같은 의미임.
<bean id="service" class="myjdbc.EmpServiceImpl">
<property name="dAO" ref="empDAO"></property>
</bean>
EmpMainSpring.java
아래코드 --> String Container가 bean을 가지고 있다가 이름을 출력하는 코드
String[] nameList = context.getBeanDefinitionNames();
for(String name : nameList) System.out.println(name);
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
myBatis 간단히 ㄱㄱ
commons maven dbcp2 repository
버전 맞게 pom.xml에 넣어주기
아래 코드 추가
<bean id="dataSource" class=";org.apache.commons.dbcp2.BasicDataSource">
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"></property>
</bean>
'공간정보아카데미' 카테고리의 다른 글
Spring - DI - Bean Annotation / 커스텀 어노테이션 만들어보기 (1) | 2025.09.01 |
---|---|
변수 vs 객체 / stack vs heap (0) | 2025.09.01 |
java - MyBatis (0) | 2025.08.29 |
Session, Cookie, Cache (0) | 2025.08.26 |
Vue - Pinia (0) | 2025.08.25 |