ÃֽŠ°Ô½Ã±Û(JAVA)
2022.03.01 / 01:52

Unable to find [jdbc]

MyData
Ãßõ ¼ö 168

tomcat¿¡ ¼Ò½º ¹èÆ÷ ½Ã ¾Æ·¡¿Í °°Àº ¸Þ½ÃÁö°¡ ¶ß°í DBÁ¢¼ÓÀÌ ¾ÈµÇ°í ¾Æ·¡¿Í °°ÀÌ ¿À·ù ¸Þ½ÃÁö°¡ ¶ã ¶§


[2017:03:23:14:31:57] DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - Returning JDBC Connection to DataSource
org.springframework.jndi.JndiLookupFailureException: JndiObjectTargetSource failed to obtain new target object; nested exception is javax.naming.NameNotFoundException: Name

[jdbc/test] is not bound in this Context. Unable to find [jdbc].

ÀÌŬ¸³½º¿¡¼­ °³¹ßÇÒ ¶§´Â DBÁ¢¼Ó Á¤º¸°¡ config ÆÄÀÏ¿¡¼­ ºÒ·¯¿À°í À־ °³¹ß ±îÁö´Â ¿¡·¯¾øÀÌ ÁøÇà Çß¾ú´Âµ¥

linux¿¡ ¹èÆ÷ÇÏ·Á°í Çϴϱñ ¹®Á¦°¡ ¹ß»ýÇϳ׿ä.

¿øÀÎÀ» ºÐ¼®ÇØ º¸´Ï ¹èÆ÷ÇÒ ¶§ »ç¿ëÇÏ´Â DBÁ¢¼Ó Á¤º¸¸¦ ¸øºÒ·¯ ¿À´Â°Å¶ó´Âµ¥ ¾Æ¹«¸® ã¾Æµµ ¿øÀÎÀ» ¸ð¸£°Ú´õ¶ó°í¿ä.


¿¹Àü¿¡ °³¹ßÇß´ø ¼­¹ö¿Í ºñ±³ÇÏ´Ù°¡ ¿øÀÎÀ» ¹ß°ßÇÏ°Ô µÇ¾ú³×¿ä.


Server.xml ÆÄÀÏÀÇ Resource tag ¸¦ »ç¿ëÇϴµ¥ tag À§Ä¡°¡ host tag¿¡ µé¾î°¡ À־ ¹ß»ýÇÑ ¹®Á¦¿´½À´Ï´Ù.

Resource tag À§Ä¡¸¦ GlobalNamingResources tag ¾È¿¡ ³ÖÀ¸´Ï ¹Ù·Î Á¢¼ÓÀÌ µÇ¾ú½À´Ï´Ù.


Tomcat ¹èÆ÷½Ã DBÁ¢¼Ó ¼³Á¤ ¹æ¹ý Á¤¸®ÇØ º¾´Ï´Ù.


WEB-INF/spring/root-context.xml

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="java:comp/env/jdbc/test"/>
        <property name="lookupOnStartup" value="false"/>
        <property name="cache" value="true"/>
        <property name="proxyInterface" value="javax.sql.DataSource"/>
</bean>


tomcat/conf/server.xml

 <GlobalNamingResources>
    <Resource name="jdbc/test"
                auth="Container"
                type="javax.sql.DataSource"
                driverClassName="com.mysql.jdbc.Driver"
                url="jdbc:mysql://localhost:3306/testdb?useUnicode=yes&amp;characterEncoding=UTF-8"
                username="..."
                password="..."
                maxActive="100"
                maxIdle="50"
                maxWait="5000"
                validationQuery="select current_date"
                removeAbandoned="true"
                removeAbandonedTimeout="60"
                logAbandoned="true" />
</GlobalNamingResources>
...

<Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true"></Host>



tomcat/conf/context.xml

 <Context>
 <ResourceLink global="jdbc/test" name="jdbc/test" type="javax.sql.DataSource"></ResourceLink>
</Context>



Server.xml¿¡ host¸íÀ» ÁöÁ¤ ÇßÀ» °æ¿ì¿¡´Â ROOT.xml ¿¡ ¸®¼Ò½º Á¤º¸¸¦ ³Ö¾îµµ µË´Ï´Ù.
<Host name="test.kr"  appBase="/home/test/public_html" unpackWARs="true" autoDeploy="true"></Host>

/usr/local/tomcat/conf/Catalina/test.kr/ROOT.xml

 <?xml version="1.0" encoding="UTF-8"?>
<Context path="/" docBase="/home/test/public_html">
<ResourceLink global="jdbc/test" name="jdbc/test" type="javax.sql.DataSource"></ResourceLink>
</Context>