Last time, I wrote JNDI with Spring Framework.


This time, I add another DB on same Spring Framework with JNDI environment.




#Tomcat setting in Server

 

- server.xml

 

1. Add new resource.


<GlobalNamingResources>

    <!-- Editable user database that can also be used by

         UserDatabaseRealm to authenticate users

    -->

    

  

    <Resource auth="Container" 

     defaultAutoCommit="false" 

     driverClassName="com.mysql.jdbc.Driver" 

     factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" 

     initialSize="10" maxActive="100" maxWait="10000" minIdle="10" 

     name="jdbc/wolfspringDS

     username="spring" 

     password="test" 

     type="javax.sql.DataSource" url="jdbc:mysql://xxx.xxx.xxx.xxx:11000/springbook" 

     validationQuery="SELECT 1 FROM DUAL"/>

    

    

    <Resource auth="Container" 

     defaultAutoCommit="false" 

     driverClassName="com.mysql.jdbc.Driver" 

     factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" 

     initialSize="10" maxActive="100" maxWait="10000" minIdle="10" 

     name="jdbc/afterrainDS" 

     username="afterrain" 

     password="test" 

     type="javax.sql.DataSource" url="jdbc:mysql://xxx.xxx.xxx.xxx:3306/afterrain" 

     validationQuery="SELECT 1 FROM DUAL"/>

               

               

    <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>

  </GlobalNamingResources>



2. Add new Context


<Context docBase="AfterRainJ" path="/openapp" reloadable="true" source="org.eclipse.jst.jee.server:AfterRainJ">

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

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

</Context>



#root-context.xml


1. add new bean


<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">

        <property name="jndiName" value="java:/comp/env/jdbc/afterrainDS" />

    </bean>

<bean id="dataSourceWolf" class="org.springframework.jndi.JndiObjectFactoryBean">

        <property name="jndiName" value="java:/comp/env/jdbc/wolfspringDS" />

</bean>



#Test JSP


<sql:query var="rs" dataSource="jdbc/afterrainDS">

select code, num, title, contents, gen_usr_id, use_flag  from mboard

</sql:query>


<sql:query var="rswolf" dataSource="jdbc/wolfspringDS">

select code, num, title, contents, gen_usr_id, use_flag  from mboard

</sql:query>



<h2>AWS Query Results</h2>

<c:forEach var="row" items="${rs.rows}">

    Code ${row.code} &nbsp;

    num ${row.num} &nbsp;

    title ${row.title} &nbsp;

    contents ${row.contents} &nbsp;

    Gen_usr_no ${row.gen_usr_id} &nbsp;

    Use_flag ${row.use_flag} &nbsp;  

    <br/> 

</c:forEach>



<h2>WolfSpring Query Results</h2>

<c:forEach var="row" items="${rswolf.rows}">

    Code ${row.code} &nbsp;

    num ${row.num} &nbsp;

    title ${row.title} &nbsp;

    contents ${row.contents} &nbsp;

    Gen_usr_no ${row.gen_usr_id} &nbsp;

    Use_flag ${row.use_flag} &nbsp;  

    <br/> 

</c:forEach>


Posted by yongwoo

블로그 이미지
No man is an island, but sometimes I feel I am an island. Every man is an island. And I stand by that.
yongwoo

공지사항

Yesterday
Today
Total

달력

 « |  » 2024.5
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 31

최근에 올라온 글

최근에 달린 댓글

글 보관함