日期:2014-05-17  浏览次数:20946 次

spring依赖注入出错,帮忙看下,急!
界面:

<form id="mainform2">
<input type="button" id="testButton" value="查询所有用户" onclick="test()">
<script type="text/javascript">
function test(){
document.getElementById("mainform2").action = "testSearchUser";
        document.getElementById("mainform2").submit();
}
</script>
</form>

action:

public class TestUserAction extends BaseAction{

@Resource
private StudentService studentService;

@Action(value="/testSearchUser",results={@Result(name="success",location="/pages/jsp/testSearchUser.jsp"),@Result (name = "error",location = "/pages/jsp/error.jsp")})
public String testSearchUser(){

List<StudentDto> studentList = studentService.studentlistsAll();

System.out.println(studentList);

return SUCCESS;
}

public StudentService getStudentService() {
return studentService;
}

public void setStudentService(StudentService studentService) {
this.studentService = studentService;
}

}

service

@Service
public class StudentService {

@Resource
private StudentMapper studentMapper; 

public  List<StudentDto> studentlistsAll(){
return studentMapper.studentlistsAll();
}
}

mapper:

@SqlMapper
public interface StudentMapper {

@Select("select * from student")
public  List <StudentDto> studentlistsAll();

}

spring配置文件配置:

<context:annotation-config />
<context:component-scan base-package="cn.com.softwise" />


然后相对应的action、service、dao都放在cn.com.softwise.wjf.action;cn.com.softwise.wjf.service;cn.com.softwise.wjf.dao;里;

然后报错:

2014-1-13 15:30:29 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'studentService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [cn.com.softwise.wjf.dao.StudentMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER)}


No ma