Mybatis 할 때
jdbc.properties에 4가지 정보 설정하고
Configuration.xml에 불러와서 사용했음
1️⃣ com.config 폴더 아래에 jdbc.properties 파일 작성
2️⃣ user.xml 등록
1) PropertyPlaceholderConfigurer
<!-- deprecated 됨 -->
<bean class="PropertyPlaceholderConfigurer">
<property name="location" value="classpath:com/config/jdbc.properties" />
</bean>
2) context namespace ⭐⭐⭐
<context:property-placeholder location="classpath: 경로" />
//context추가 필요
xmlns:context="http://www.springframework.org/schema/context"
//스키마Loaction 추가 필요
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<context:property-placeholder location="classpath:com/config/jdbc.properties" /> // .properties경로
3️⃣ 임의의 빈에서 ${key} 방법으로 4개의 데이터 값을 주입받는다.
<bean id="service" class="com.service.UserService">
<!-- 4개의 데이터 주입받기 -->
<property name="driver" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="userid" value="${jdbc.username}" />
<property name="passwd" value="${jdbc.password}" />
</bean>
💻 결과
'Framework > SPRING FRAMEWORK' 카테고리의 다른 글
TestMain이 아닌 일반클래스(빈, UserService)에서 사용하는 방법 (0) | 2023.08.29 |
---|---|
I18N - 국제화(지역화) (0) | 2023.08.29 |
profile (0) | 2023.08.29 |
현재 실행중인 운영체제의 환경변수 값 살펴보기 (0) | 2023.08.29 |
life cycle 콜백 메서드 (0) | 2023.08.29 |