Spring 프레임 워 크 (3) -- Spring 설정 데이터 원본
C3P 0 데이터 원본 (C3P 0 연결 풀) 의 경우 스프링 이 '사용자 정의 대상 이 아 닌' 에 대한 설정 을 보 여 줍 니 다.
Spring 에서 C3P 0 링크 풀 을 설정 하 는 단계:
1. 데이터 원본 의 좌표 와 데이터 베 이 스 를 가 져 오 는 구동 좌표
1
2
3 c3p0
4 c3p0
5 0.9.1.2
6
7
8
9
10 mysql
11 mysql-connector-java
12 5.1.39
13
2. 데이터 원본 의 기본 링크 데이터 설정
C3P 0 링크 풀 을 수 동 으로 만 들 고 Spring 설정 C3P 0 링크 풀 을 사용 합 니 다.
Spring 설정 사용: 핵심 설정 파일 에 다음 과 같이 설정 합 니 다.
1 "dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
2 "driverClass" value="com.mysql.jdbc.Driver"/>
3 "jdbcUrl" value="jdbc:mysql://localhost:3306/test"/>
4 "user" value="root"/>
5 "password" value="root"/>
6
최적화 설정: value 후의 값 을 새로운 프로필 jdbc. properties 로 추출 합 니 다.
1 jdbc.driver=com.mysql.jdbc.Driver
2 jdbc.url=jdbc:mysql://localhost:3306/test
3 jdbc.username=root
4 jdbc.password=root
그리고 핵심 프로필 의 내용 을 수정 합 니 다. 핵심 프로필 에 프로필 을 도입 합 니 다.
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
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.xsd">
class="com.mchange.v2.c3p0.ComboPooledDataSource">
수 동: 테스트 클래스 에서 작성 하여 실행 합 니 다. 일반적으로 이 방법 을 사용 하지 않 습 니 다.
1 @Test
2 public void testC3P0() throws Exception {
3 //
4 ComboPooledDataSource dataSource = new ComboPooledDataSource();
5 //
6 dataSource.setDriverClass("com.mysql.jdbc.Driver");
7 dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/test");
8 dataSource.setUser("root");
9 dataSource.setPassword("root");
10 //
11 Connection connection = dataSource.getConnection();
12 System.out.println(connection);
13 }
3. 데이터 원본 대상 을 만 들 고 데이터 원본 을 사용 하여 연결 자원 을 가 져 오고 연결 자원 을 반환 합 니 다.
테스트 클래스 에서 작성:
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
DataSource dataSource = (DataSource) applicationContext.getBean("dataSource");
Connection connection = dataSource.getConnection();
System.out.println(connection);
데이터 원본 을 성공 적 으로 만 들 었 는 지 실험 할 수 있 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.