刚开始学Spring 和jndi,按照网上的配置写的代码如下,但是总是不能输出需要的代码 ,但是 使用 ds = (DataSource) ctx.lookup("jdbc/zxdy"); 的方法能够正确获取数据源
,请各位大侠帮我分析一下,多多指点,不胜感激!
第一步 context的配置文件为
<Context>
<Resource
driverClassName="com.mysql.jdbc.Driver"
name="jdbc/zxdy"
auth="Container"
type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="123456"
url="jdbc:mysql://localhost:3306/zxdy"/>
</Context>
第二步 applicationcontext.xml
<beans default-autowire="byName"
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<!--通过JNDI获得数据源的引用-->
<bean id="zxdyDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/zxdy</value>
</property>
</bean>
<!-- 配置JdbcTemplate的bean -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource">
<ref local="zxdyDataSource"/>
</property>
</bean>
<!-- 配置DBUtil的bean 并注入资源-->
http://c.tieba.baidu.com/p/3476776824
http://c.tieba.baidu.com/p/3476808306
http://c.tieba.baidu.com/p/3476798710
http://c.tieba.baidu.com/p/3474281354
http://c.tieba.baidu.com/p/3474300101
http://c.tieba.baidu.com/p/3474294075
http://c.tieba.baidu.com/p/3474123295
http://c.tieba.baidu.com/p/3474314242
http://c.tieba.baidu.com/p/3474310411
http://c.tieba.baidu.com/p/3474304550
http://c.tieba.baidu.com/p/3475433945
http://c.tieba.baidu.com/p/3475430015
http://c.tieba.baidu.com/p/3475433348
http://c.tieba.baidu.com/p/3475431434
http://c.tieba.baidu.com/p/3474176863
http://c.tieba.baidu.com/p/3474159835
http://c.tieba.baidu.com/p/3474163941
http://c.tieba.baidu.com/p/3474156121
http://c.tieba.baidu.com/p/3474147660
http://c.tieba.baidu.com/p/3474151899
http://c.tieba.baidu.com/p/3474142287
http://c.tieba.baidu.com/p/3474136965
http://c.tieba.baidu.com/p/3474133165
http://c.tieba.baidu.com/p/3474128675
http://c.tieba.baidu.com/p/3474103896
http://c.tieba.baidu.com/p/3474099488
http://c.tieba.baidu.com/p/3474094120
http://c.tieba.baidu.com/p/3475431976
http://c.tieba.baidu.com/p/3474267991
http://c.tieba.baidu.com/p/3474259583
http://c.tieba.baidu.com/p/3474254990
http://c.tieba.baidu.com/p/3474228986
http://c.tieba.baidu.com/p/3474221626
http://c.tieba.baidu.com/p/3474215742
http://c.tieba.baidu.com/p/3474212122
http://c.tieba.baidu.com/p/3474188883
http://c.tieba.baidu.com/p/3474207722
http://c.tieba.baidu.com/p/3474184143
http://c.tieba.baidu.com/p/3474180522
http://c.tieba.baidu.com/p/3474171022
http://c.tieba.baidu.com/p/3474086627
http://c.tieba.baidu.com/p/3462847203
http://c.tieba.baidu.com/p/3462839334
http://c.tieba.baidu.com/p/3462834294
http://c.tieba.baidu.com/p/3462786130
http://c.tieba.baidu.com/p/3462782768
http://c.tieba.baidu.com/p/3461791753
http://c.tieba.baidu.com/p/3461784215
http://c.tieba.baidu.com/p/3461778008
http://c.tieba.baidu.com/p/3461772860
http://c.tieba.baidu.com/p/3461767442
http://c.tieba.baidu.com/p/3461736231
http://c.tieba.baidu.com/p/3461704953
http://c.tieba.baidu.com/p/3461692676
http://c.tieba.baidu.com/p/3461665341
http://c.tieba.baidu.com/p/3461656389
http://c.tieba.baidu.com/p/3461660595
http://c.tieba.baidu.com/p/3461566608
http://c.tieba.baidu.com/p/3461652243
http://c.tieba.baidu.com/p/3461561596
http://c.tieba.baidu.com/p/3461557067