상황: maven jetty 6.1.14 에 DataSource를 설정하고 개발환경을 구축하여 개발하는 도중 REST 로 개발되어야 할 상황이 발생하여 strusts2-rest-plugin 2.1.6으로 개발환경을 구축하였으나 동작하지 않음. 정확한 원인은 모르겠으나 Jetty 환경에서 REST 적용이 안되는 것 같아서 WST 환경으로 전환함. 이때 Jetty Server가 설치되어 있지 않은 관계로 Tomcat 6.0 으로 Server 설정을 했으나 Jetty의 JNDI 설정을 인식하지 못함.
목적: Jetty 와 Tomcat 개발환경에서 설정변경없이 동시에 개발하고 싶다.
--------
Jetty 6.1.14 에서 기본 JNDI 작업
:jetty.xml
: applicationContext.xml(spring 설정)
: web.xml (만약 설정한다면)
Tomcat 6.0에서 JNDI 작업
:server.xml(tomcat 설정)
:context.xml(tomcat 설정)
: applicationContext.xml(spring 설정)
: web.xml(web 설정)
Jetty 6.1.14에서 Tomcat 6.0과 같이 작업하기
핵심은 'java:comp/env'를 인식하게 만드는것.
참조 URL : http://docs.codehaus.org/display/JETTY/JNDI
:jetty.xml
: applicationContext.xml(spring 설정)
: web.xml(web 설정)
위와 같이 함으로써 Tomcat 6.0과 Jetty 6.1.14에서 JNDI를 동일한 방식으로 접근할 수 있으므로 개발에 편리성을 제공한다.
결국 java:comp/env 를 어떻게 인식시키느냐가 핵심이었다는 것...
목적: Jetty 와 Tomcat 개발환경에서 설정변경없이 동시에 개발하고 싶다.
--------
Jetty 6.1.14 에서 기본 JNDI 작업
:jetty.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure 1.1//EN" "http://jetty.mortbay.org/configure_1_2.dtd">
<Configure class="org.mortbay.jetty.Server">
<New id="NEXFA_DS" class="org.mortbay.jetty.plus.naming.Resource">
<Arg></Arg>
<Arg>java:NEXFA_DS</Arg>
<Arg>
<New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
<Set name="Url">jdbc:mysql://localhost:3306/nexfadb</Set>
<Set name="User">nexfa</Set>
<Set name="Password">nexfa</Set>
</New>
</Arg>
</New>
</Configure>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure 1.1//EN" "http://jetty.mortbay.org/configure_1_2.dtd">
<Configure class="org.mortbay.jetty.Server">
<New id="NEXFA_DS" class="org.mortbay.jetty.plus.naming.Resource">
<Arg></Arg>
<Arg>java:NEXFA_DS</Arg>
<Arg>
<New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
<Set name="Url">jdbc:mysql://localhost:3306/nexfadb</Set>
<Set name="User">nexfa</Set>
<Set name="Password">nexfa</Set>
</New>
</Arg>
</New>
</Configure>
: applicationContext.xml(spring 설정)
...
<bean id="nexfaDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:NEXFA_DS" />
</bean>
...
<bean id="nexfaDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:NEXFA_DS" />
</bean>
...
: web.xml (만약 설정한다면)
...
<resource-ref>
<description>Nexfa Mysql Datasource</description>
<res-ref-name>java:NEXFA_DS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
...
<resource-ref>
<description>Nexfa Mysql Datasource</description>
<res-ref-name>java:NEXFA_DS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
...
Tomcat 6.0에서 JNDI 작업
:server.xml(tomcat 설정)
...
<GlobalNamingResources>
<!-- Added Resource -->
<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" name="jdbc/NEXFA_DS"
username="nexfa" password="nexfa" url="jdbc:mysql://localhost:3306/nexfadb?autoReconnect=true"
logAbandoned="true" maxActive="1000" maxIdle="30" maxWait="180" removeAbandoned="true"
removeAbandonedTimeout="60" type="javax.sql.DataSource" />
</GlobalNamingResources>
...
<GlobalNamingResources>
<!-- Added Resource -->
<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" name="jdbc/NEXFA_DS"
username="nexfa" password="nexfa" url="jdbc:mysql://localhost:3306/nexfadb?autoReconnect=true"
logAbandoned="true" maxActive="1000" maxIdle="30" maxWait="180" removeAbandoned="true"
removeAbandonedTimeout="60" type="javax.sql.DataSource" />
</GlobalNamingResources>
...
:context.xml(tomcat 설정)
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<!-- Added -->
<ResourceLink global="jdbc/NEXFA_DS" name="jdbc/NEXFA_DS" type="javax.sql.DataSource"/>
</Context>
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<!-- Added -->
<ResourceLink global="jdbc/NEXFA_DS" name="jdbc/NEXFA_DS" type="javax.sql.DataSource"/>
</Context>
: applicationContext.xml(spring 설정)
...
<bean id="nexfaDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/NEXFA_DS" />
</bean>
...
<bean id="nexfaDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/NEXFA_DS" />
</bean>
...
: web.xml(web 설정)
...
<resource-ref>
<description>Nexfa Mysql Datasource</description>
<res-ref-name>jdbc/NEXFA_DS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
...
<resource-ref>
<description>Nexfa Mysql Datasource</description>
<res-ref-name>jdbc/NEXFA_DS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
...
Jetty 6.1.14에서 Tomcat 6.0과 같이 작업하기
핵심은 'java:comp/env'를 인식하게 만드는것.
참조 URL : http://docs.codehaus.org/display/JETTY/JNDI
:jetty.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure 1.1//EN" "http://jetty.mortbay.org/configure_1_2.dtd">
<Configure class="org.mortbay.jetty.Server">
<New id="NEXFA_DS" class="org.mortbay.jetty.plus.naming.Resource">
<Arg></Arg>
<Arg>jdbc/NEXFA_DS</Arg>
<Arg>
<New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
<Set name="Url">jdbc:mysql://localhost:3306/nexfadb</Set>
<Set name="User">nexfa</Set>
<Set name="Password">nexfa</Set>
</New>
</Arg>
</New>
</Configure>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure 1.1//EN" "http://jetty.mortbay.org/configure_1_2.dtd">
<Configure class="org.mortbay.jetty.Server">
<Array id="plusConfig" type="java.lang.String">
<Item>org.mortbay.jetty.webapp.WebInfConfiguration</Item>
<Item>org.mortbay.jetty.plus.webapp.EnvConfiguration</Item>
<Item>org.mortbay.jetty.plus.webapp.Configuration</Item>
<Item>org.mortbay.jetty.webapp.JettyWebXmlConfiguration</Item>
<Item>org.mortbay.jetty.webapp.TagLibConfiguration</Item>
</Array>
<New id="nexfaWebAppContext" class="org.mortbay.jetty.webapp.WebAppContext">
<Set name="ConfigurationClasses"><Ref id="plusConfig"/></Set>
</New>
<Item>org.mortbay.jetty.webapp.WebInfConfiguration</Item>
<Item>org.mortbay.jetty.plus.webapp.EnvConfiguration</Item>
<Item>org.mortbay.jetty.plus.webapp.Configuration</Item>
<Item>org.mortbay.jetty.webapp.JettyWebXmlConfiguration</Item>
<Item>org.mortbay.jetty.webapp.TagLibConfiguration</Item>
</Array>
<New id="nexfaWebAppContext" class="org.mortbay.jetty.webapp.WebAppContext">
<Set name="ConfigurationClasses"><Ref id="plusConfig"/></Set>
</New>
<New id="NEXFA_DS" class="org.mortbay.jetty.plus.naming.Resource">
<Arg></Arg>
<Arg>jdbc/NEXFA_DS</Arg>
<Arg>
<New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
<Set name="Url">jdbc:mysql://localhost:3306/nexfadb</Set>
<Set name="User">nexfa</Set>
<Set name="Password">nexfa</Set>
</New>
</Arg>
</New>
</Configure>
: applicationContext.xml(spring 설정)
...
<bean id="nexfaDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/NEXFA_DS" />
</bean>
...
<bean id="nexfaDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/NEXFA_DS" />
</bean>
...
: web.xml(web 설정)
...
<resource-ref>
<description>Nexfa Mysql Datasource</description>
<res-ref-name>jdbc/NEXFA_DS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
...
<resource-ref>
<description>Nexfa Mysql Datasource</description>
<res-ref-name>jdbc/NEXFA_DS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
...
위와 같이 함으로써 Tomcat 6.0과 Jetty 6.1.14에서 JNDI를 동일한 방식으로 접근할 수 있으므로 개발에 편리성을 제공한다.
결국 java:comp/env 를 어떻게 인식시키느냐가 핵심이었다는 것...