这是错误
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就出错 不知道什么原因 跪求解答
@Resource
private UserDao userDao;
把这个resource改成@Autowired试试
UserController的bean配置prototype是算认为懒加载的,即每次调用的时候才会创建bean,所以你启动服务器没问题,登录时候依赖到UserController就因为bean创建失败报错了。错误提示说userService没有指定userDao导致了这个错误,可能是userDao生成出了问题,你把mtbatis的配置文件贴出来看一下
resource是responsebody和Autowired的结合,所以看情况而定,用Autowired试试
我是楼主 这是mybaitis 的配置
<?xml version="1.0" encoding="UTF-8"?>
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd" >
<!-- 自动扫描mapping.xml文件 -->
classpath:mapper/*.xml
<!-- Mapper接口所在包,Spring会自动查找其下的Mapper -->
<!-- 自动扫描mapping.xml文件 -->
classpath:mapper/*.xml
<!-- Mapper接口所在包,Spring会自动查找其下的Mapper -->
我也发生这个情况,之前ssm项目还正常使用,放几天就坏了报500找不到Action,原因是eclipse
,你使用spring定制版eclipse吧,和eclipse一样,修复了很多bug,你重新创建一个项目,把代码粘进去,就好了
https://spring.io/tools3/sts/legacy STS各种版本