Spring + JNDI DateSource

env: tomcat5.5 + spring2.5

 

in server.xml insert

 

<Context...>

...

<Resource name="jdbc/DS" auth="Container"
            type="javax.sql.DataSource"
            factory="org.apache.commons.dbcp.BasicDataSourceFactory"
            username="username"
            password="password"
            driverClassName="com.mysql.jdbc.Driver"
            url="jdbc:mysql:..."
            maxActive="5"
            maxIdle="3"
            maxWait="100"
            />

 

...

</Context>

 

put commons-collections.jar, commons-dbcp.jar, commons-pool.jar, mysql-connector-java-bin.jar into ${tomcat_home}/common/lib

 

modify spring appContext.xml append:

 

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="java:comp/env/jdbc/DS"/>
    </bean>

 

add spring-context.jar in project classpath.

 

Good luck!

你可能感兴趣的:(spring,tomcat,bean,mysql,jdbc)