I am using tomcat-5.5, Mysql 5.1.27, Spring 3.0
Keep all the Spring libraries in D:\apache-tomcat\webapps\SpringWeb\WEB-INF\lib
Copy the JDBC Connector library in D:\apache-tomcat\common\lib
I first created a datasource on tomcat.
Modify the D:\apache-tomcat\conf\context.xml file to include this tag.
< resource auth="Container"
driverclassname="com.mysql.jdbc.Driver"
maxactive="100" maxidle="30" maxwait="10000"
name="jdbc/HWMD_DS"
password="pratik"
type="javax.sql.DataSource"
url="jdbc:mysql://localhost:3306/HOW_WAS_MY_DAY"
username="pratik"
/>
I am using plain JDBC with Spring to connect to the database.
This is how the Spring configuration file will look like.
< beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xsi:schemalocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">
< bean class="org.springframework.jndi.JndiObjectFactoryBean" id="dataSource" scope="singleton">
< property name="jndiName" value="java:/comp/env/jdbc/HWMD_DS">
< property name="resourceRef" value="false">
< bean class="org.springframework.jdbc.core.JdbcTemplate" id="jdbcTemplate">
< property name="dataSource" ref="dataSource">
< bean class="dave.spring.dao.JdbcRantDao" id="rantDao">
< property name="jdbcTemplate" ref="jdbcTemplate">
This Spring configuration should be in application classpath. ie
D:\apache-tomcat\webapps\SpringWeb\WEB-INF\classes\myapp-dao.xml
No comments:
Post a Comment