<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!-- the test application context definition for the jdbc based tests -->
<bean id="productDao" class="springapp.repository.JdbcProductDao">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
</beans>
=================================
Document path
C:\spring\util\apache-tomcat-5.5.27\webapps\tomcat-docs\index.html
8) JNDI Resources
4. Configure Tomcat's Resource Factory
To configure Tomcat's resource factory, add an elements like this to the $CATALINA_HOME/conf/server.xml
file, nested inside the Context
element for this web application.
![]() |
![]() |
![]() |
![]() |
<Context ...> ... <Resource name="bean/MyBeanFactory" auth="Container" type="com.mycompany.MyBean" factory="com.mycompany.MyBeanFactory" bar="23"/> ... </Context> |
![]() |
![]() |
![]() |
![]() |
Note that the resource name (here, bean/MyBeanFactory
must match the value specified in the web application deployment descriptor. We are also initializing the value of the bar
property, which will cause setBar(23)
to be called before the new bean is returned. Because we are not initializing the foo
property (although we could have), the bean will contain whatever default value is set up by its constructor.
tomcat Server.xml 설정
<GlobalNamingResources>
<Resource name="jdbc/SpringDB" auth="Container"
type="javax.sql.DataSource" username="spring" password="spring123"
driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@localhost:1521:XE"
maxActive="8" maxIdle="4"/>
</GlobalNamingResources>
맨밑에
<Context docBase="spring_1"
path="/spring_1"
reloadable="true"
source="org.eclipse.jst.j2ee.server:spring_1">
<ResourceLink name="jdbc/SpringDB"
global="jdbc/SpringDB"
type="javax.sql.DataSource"/>
</Context>
설정 하고 나서 Test_jndi.jsp 만들어서 Test를 해봅시다.
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="java.sql.*" %>
<%@ page import="javax.naming.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<% InitialContext ctx = new InitialContext();
Object obj = ctx.lookup("java:comp/env/jdbc/SpringDB");
if(obj != null)
{
javax.sql.DataSource ds = (javax.sql.DataSource)obj;
Connection conn = ds.getConnection();
Statement stmt = conn.createStatement();
String sql = "SELECT * FROM BOARD ";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next())
{
out.println(rs.getString(1) + "<br>");
}
stmt.close();
conn.close();
}
else {
out.println("검색 실패 !!");
}
%>
</body>
</html>