반응형
출처
http://egloos.zum.com/utils/v/3853335
JNDI를 이용해서 웹어플의 ConnectionPool 구현 중 모르는것이 나타났다.
java:comp/env
-전형적인 DataSource 구현 방법
//Obtain our environment naming context
Context initCtx = new InitialContext();
Context envCtx = (Context)initCtx.lookup("java:comp:env");
//DataSource 를 검색
//"jdbc/mysql은 web.xml과 context.xml에 설정되어 있는 name값
DataSource ds = (DataSource)encCtx.lookup("jdbc/mysql");
//커센션 풀로부터 커넥션 얻기
Connection c = da.getConnection();
위의 코드에서 "java:comp:env" 가 도대체 뭘까?!?!
톰캣 홈페이지의 유저가이드를 확인해봤다.
http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html
The InitialContext is configured as a web application is initially deployed, and is made available to web application components (for read-only access). All configured entries and resources are placed in the java:comp/env portion of the JNDI namespace
java:comp/env는 웹어플의 구성된 엔트리와 리소스들이 배치 되어있는 부분.
그래서 이곳에 접근 하여 web.xml의 <resource-env-ref>에 설정한 jdbc/mysql과 매핑되는 리소스를 가져온다.
톰캣의 리소스 팩토리를 구성하기 위해 <Context>엘리먼트를 추가해야한다.
일종의 추가 정보를 추가한다고 이해하면 된다.
반응형
'Programming Language > Java' 카테고리의 다른 글
에러 / Dangling meta character '*' near index 0 (0) | 2018.09.10 |
---|---|
[Java] System.nanoTime() 이용하여, 함수 실행 시간 log를 남기고 싶을 때는? (0) | 2018.09.06 |
mysql db 연동 테스트 (0) | 2018.07.04 |
[Java] retainAll() 로 두 list의 중복 요소 제거 (0) | 2018.06.14 |
[Java] 자바 인코딩 new String( ... , 'EUC-KR') (0) | 2018.05.29 |