springMVC使用JNDI连接数据库

service.xmldataSource

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

web.xml

<resource-ref>
	  <description>DB Connection</description>
	  <res-ref-name>jdbc/Siw</res-ref-name>
	  <res-type>javax.sql.DataSource</res-type>
	  <res-auth>Container</res-auth>
</resource-ref>

comcatcontext.xml

<Resource name="jdbc/Siw" auth="Container" type="javax.sql.DataSource"
           maxActive="100" maxIdle="30" maxWait="10000"
           username="sa" password="sa" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
           url="jdbc:sqlserver://localhost:1433;databaseName=siw"/>

comcatserver.xml

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

相关推荐