这是错误
Request processing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.user.dao.UserDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotationsjavax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)}
这是配置
<!-- spring mvc 注解及类型转换 -->
class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<!-- spring mvc 视图解析器 -->
<!-- 定义跳转的文件的前后缀 ,视图模式配置 -->
<!-- 自动给后面action的方法return的字符串加上前缀和后缀,变成一个 可用的url地址 -->
<!-- 文件上传需要配置此解析器
找类的快捷键为:ctrl+shift+t
查看本类方法:ctrl+o,假如想继续看父类方法继续ctrl+o
-->
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- 默认编码 -->
<!-- 文件大小最大值 -->
<!-- 内存中的最大值 -->
这是mybatis的配置
<!-- 自动扫描mapping.xml文件 -->
classpath:mapper/*.xml
<!-- Mapper接口所在包,Spring会自动查找其下的Mapper -->
这是dao
@Repository
public interface UserDao {
public User findUserByUserNameAndPassword(@Param("userName") String userName, @Param("password") String password);
public int addUser(User user);
}
这是service 接口没贴出来 就两个方法
@Service
public class UserServiceImpl implements UserService {
@Resource
private UserDao userDao;
public User login(String userName, String password) {
return userDao.findUserByUserNameAndPassword(userName, password);
}
public Integer register(User user) {
return userDao.addUser(user);
}
这是controller
@Scope(value="prototype")
@RequestMapping("/user")
@Controller
public class UserController {
@Resource
private UserService userService;
@RequestMapping("toLogin")
public String toLogin(){
System.out.println("1111111111");
return "user/login";
}
这是web.xml
Archetype Created Web Application
dispatcherServlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:spring-mvc.xml
1
dispatcherServlet
*.do
index.jsp
tomcat可以运行 到首页放问toLogin.do就出错 不知道什么原因 跪求解答