运行时出现的异常: 启动类: import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; @SpringBootApplication(exclude = DataSourceAutoConfiguration.class) @MapperScan("com.extjs.mapper") public class ExtjsdemoApplication { public static void main(String[] args) { SpringApplication.run(ExtjsdemoApplication.class, args); } } application.yml配置文件 我的依赖就这几个 User实体类: public class User { private Integer id; private String username; private String password; private Integer roleid; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public Integer getRoleid() { return roleid; } public void setRoleid(Integer roleid) { this.roleid = roleid; } } mapper接口: package com.extjs.mapper; import com.extjs.entity.User; import org.apache.ibatis.annotations.Select; public interface UserMapper { @Select("select * from where id=#{id}") User selectByid(Integer id); } 我也试过在接口里面加@mapper注解,但是也没用,依然注入失败。 package com.extjs.controller; import com.extjs.entity.User; import com.extjs.mapper.UserMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.ModelAndView; @Controller @RestController public class UserController { @Autowired private UserMapper userMapper; @RequestMapping(value = "index") public String index(ModelAndView model){ User user =userMapper.selectByid(1); model.addObject("name",user.getUsername()); return "index"; } } 我是刚开始接触springboot的,这个问题困扰了3天了,我想问下各位大佬是怎么解决的? 下面是异常翻译过了的: beans.factory。创建名为“userController”的bean时出错:通过字段“userMapper”表示的未满足的依赖项;嵌套异常是org.springframe .bean .factory。BeanCreationException:在文件中定义名称为“userMapper”的bean创建时出错 (责任编辑:) |