用的Mybatis+Spring
贴出我的applicationContext配置、?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation=" http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:component-scan base-package="autoPage" /><bean id="commentDao" class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface" value="com.mimi.dao.CommentDao"></property>
<property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
</bean>
<bean id="commentService" class="com.mimi.service.impl.CommentServiceImpl">
<property name="commentDao" ref="commentDao"></property>
</bean>
<bean id="commentModule" class="com.mimi.module.CommentModule">
<property name="commentService" ref="commentService"></property>
</bean>
只贴出的了重点。
然后我在Action(commentModule)中是这么用的。private CommentService commentService; public CommentService getCommentService() {
return commentService;
} public void setCommentService(CommentService commentService) {
this.commentService = commentService;
}然后就NullPointerExeception 了。
指定是注入失败。因为的在Class中手动getBean测试都成功了。。求大神指点,我是哪里不对。还是思路有问题。谢谢
贴出我的applicationContext配置、?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation=" http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:component-scan base-package="autoPage" /><bean id="commentDao" class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface" value="com.mimi.dao.CommentDao"></property>
<property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
</bean>
<bean id="commentService" class="com.mimi.service.impl.CommentServiceImpl">
<property name="commentDao" ref="commentDao"></property>
</bean>
<bean id="commentModule" class="com.mimi.module.CommentModule">
<property name="commentService" ref="commentService"></property>
</bean>
只贴出的了重点。
然后我在Action(commentModule)中是这么用的。private CommentService commentService; public CommentService getCommentService() {
return commentService;
} public void setCommentService(CommentService commentService) {
this.commentService = commentService;
}然后就NullPointerExeception 了。
指定是注入失败。因为的在Class中手动getBean测试都成功了。。求大神指点,我是哪里不对。还是思路有问题。谢谢
解决方案 »
- 需要JSP开发的公司人事管理系统(数据库需是SQL 或者MS ACCESS) 毕业设计用
- 计数器问题再次请教,如何实现一个确保不会自动清0的计数器?
- 如何将tr的id设置为变量??????
- 30分!jsp里说的"报头"如何理解!
- 有一个多选功能大概有100项,不能用checkbox,大家还有其他好的多选方法嘛?分不够可以加,解决马上给分
- 编辑框中写入和写入到数据库中的格式不统一的问题???谢谢各位大虾
- 怎么样才能控制图片的点击效果?让图片点击时,换张图
- 如何屏蔽通过敲jsp页面的路径访问页面
- 为什么不能取得带()之类的参数
- 使用jspsmartupload遇到的奇怪问题!
- GeoServer+OpenLayers中的鹰眼地图(OverviewMap)不显示,急。。。
- css,js的问题,求大神们帮忙,急急急!
人品啊哥们、你换一换名称试试!!!
commentService换成commentToService什么的、然后在试试~~~有时候我遇到这些莫名奇妙的问题、就是这样、换名称、尽量区别开来!
你用的是注解吗?先看看action
另外你这句是干什么的<context:component-scan base-package="autoPage" />。
你的base-package不是autoPage吧
我用的是Module 。基于Servlet的类。 那个CommentModule就类似于Action
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext.xml,classpath:applicationContext.xml,classpath*:applicationContext-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>Xml是这样配置的