我得到以下异常:
org.springframework.beans.factory.NoSuchBeanDefinitionException:没有找到符合条件的 bean [pers.panxin.springboot.demo.mapper.UserMapper] 类型的依赖项:预计至少有 1 个 bean 有资格作为此依赖项的自动装配候选者。依赖注解:{@org.springframework.beans.factory.annotation.Autowired(required=true)}
控制器 :
@Controller
public class HelloController {
@Autowired
private UserService userService;
@RequestMapping("/userList")
@ResponseBody
public String getAllUser(){
return "userList : "+userService.getAllUser().toString();//+list.toString();
}
}
服务:
public interface UserService {
public String getString();
public List<User> getAllUser();
}
服务实现:
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Override
public String getString() {
return "something else ... ";
}
@Override
public List<User> getAllUser() {
return userMapper.getAllUser();
}
}
映射器接口:
@Service
public interface UserMapper {
/**
* @return
*/
public List<User> getAllUser();
}
应用程序的主类
@ComponentScan
@EnableAutoConfiguration
@SpringBootApplication
public class ApplicationStarter {
public static void main(String[] args) {
SpringApplication.run(ApplicationStarter.class, args);
}
}
异常是如何发生的或我的代码中有什么问题?