ibatis+spring 注入的DAO总是空指针

shuaiAWP 2011-10-18 04:56:38
这是applicationContextv.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">


<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver
</value>
</property>
<property name="url">
<value> jdbc:mysql://localhost:3306/test
</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>root</value>
</property>
</bean>

<!-- 集成ibatis -->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="WEB-INF/sqlmap-config.xml" />
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<bean id="personDao" class="com.gogoosoft.dao.impl.PersonDaoImp">
<property name="sqlMapClient" ref="sqlMapClient"></property>
</bean>
<bean id="loginAction" class="com.gogoosoft.action.LoginAction">
<property name="personDao" ref="personDao"></property>
</bean>
</beans>




在loginAction里调用personDao,总是空指针,求解,捣鼓一天了
...全文
241 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
shuaiAWP 2011-10-18
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 csh624366188 的回复:]
这是spring吗??
[/Quote]

。。
曹胜欢 2011-10-18
  • 打赏
  • 举报
回复
这是spring吗??
shuaiAWP 2011-10-18
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 yexiongmybh 的回复:]
对了,,你这个是struts1,要在struts-config.xml里面配置一个control或者是plug-in


plug-in是这么配的,不过要加一个plug-in的插件包的,包名叫“spring-webmvc-struts.jar”


XML code

<plug-in

className="org.springframework.web.st……
[/Quote]

我用的struct2,还是不行啊
yexiongMYBH 2011-10-18
  • 打赏
  • 举报
回复
对了,,你这个是struts1,要在struts-config.xml里面配置一个control或者是plug-in


plug-in是这么配的,不过要加一个plug-in的插件包的,包名叫“spring-webmvc-struts.jar”


<plug-in

className="org.springframework.web.struts.ContextLoaderPlugIn">

<set-property property="contextConfigLocation"

value="/WEB-INF/applicationContext.xml" />

</plug-in>


control这么配


<controller>

<set-property property="processorClass" value="org.springframework.web.struts.DelegatingRequestProcessor" />

</controller>
yexiongMYBH 2011-10-18
  • 打赏
  • 举报
回复
就是这个applicationContext.xml。。
shuaiAWP 2011-10-18
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 yexiongmybh 的回复:]
personDao在action里面是要有相关的get和set方法的。还有,那个personDao是要和Spring的配置文件里面一样的。
[/Quote]

spring还需要别的配置文件吗?不就是一个applicationContext。xml吗
yexiongMYBH 2011-10-18
  • 打赏
  • 举报
回复
personDao在action里面是要有相关的get和set方法的。还有,那个personDao是要和Spring的配置文件里面一样的。
lyhmy 2011-10-18
  • 打赏
  • 举报
回复
额,不会啊,dao、action都有注入了啊,你的personDao在action中有set\get()方法吗,别忘记它了
shuaiAWP 2011-10-18
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 vikenchen 的回复:]
personDao在spring那里注入了没
[/Quote]

什么意思?
vikenchen 2011-10-18
  • 打赏
  • 举报
回复
personDao在spring那里注入了没

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧