막상 급하게 하려고 하면 은근 귀찮은 작업이라 메모해 둔다.

tomcat 단독으로 로컬에서 세팅해야 할때

그런데 아래 방법으로 하였더니 잘 되다가 어느 순간 eclipse에서 jndi를 찾지

못하는 경우가 있었다. 이 경우 수없는 삽질끝에 찾은 방법이

Resource 부분을 server.xml 에 넣으면 되지 않고, context.xml 에 넣었더니

잘 되었다. 어떤 차이가 있어서일까?


1 설정 순서

 1) server.xml 의 데이터베이스 세부 설정

 2) lib 디렉토리에 jar, jdbc 드라이버 저장

 3) 애플리케이션 web.xml 에 jndi 정의

 4) spring 에서 jndi 정의


2 server.xml 설정

 - 전역 설정

<Resource auth="Container" name="jdbc/postgres" type="javax.sql.DataSource" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" driverClassName="org.postgresql.Driver"
        url="jdbc:postgresql://100.100.1.100:5432/test" username="test" password="test"  initialSize="10" maxActive="100" maxIdle="50" minIdle="10" />


<Resource type="javax.sql.DataSource" name="jdbc/TestDB" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
    driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/mysql" username="mysql_user" password="mypassword123"
    initialSize="10" maxActive="100" maxIdle="50" minIdle="10" />


3 jdbc dirver 저장

 - D:\tomcat\tomcat7\lib\postgresql-9.3-1102.jdbc41.jar

 - CATALINA_HOME/lib/tomcat-dbcp.jar 에 있는지 확인


4 web.xml 설정

     <resource-ref>
        <description>DB Connection</description>
        <res-ref-name>jdbc/postgres</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>


5 spring 설정 파일 jndi 설정

Posted by gt1000

블로그 이미지
gt1000

태그목록

공지사항

어제
오늘

달력

 « |  » 2024.4
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함