关键代码
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/ghdb</value>
</property>
<property name="resourceRef">
<value>true</value>
</property>
</bean>
全局jndi配置
Tomcat7\conf\context.xml下新增如下代码
<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver"
logAbandoned="true" maxActive="20" maxIdle="10" maxWait="1000" name="jdbc/ghdb"
password="root" removeAbandoned="true" removeAbandonedTimeout="60"
type="javax.sql.DataSource"
url="jdbc:mysql://127.0.0.1:3306/kdddb?generateSimpleParameterMetadata=true&characterEncoding=utf8&autoReconnect=true"
useUnicode="true"
username="root" />
注意
name="jdbc/ghdb"和
<property name="jndiName">
<value>java:comp/env/jdbc/ghdb</value>
</property>