Can't wire layers in Spring Boot | MyBatis application. The problem is probably happening when Service layer uses Mapper.
Controller method sample:
@Controller
@RequestMapping("demo")
public class MessageController {
@Autowired
private MessageService messageService;
@RequestMapping(value = "messages", method = RequestMethod.GET)
public String getMessages(ModelMap modelMap) {
modelMap.addAttribute(MESSAGE,
messageService.selectMessages());
return "messages";
}
Service class:
@Service
public class MessageService {
@Autowired // Not sure if I can use Autowired here.
private MessageMapper messageMapper;
public MessageService() {
}
public Collection<Message> selectMessages() { return
messageMapper.selectAll(); }
}
MyBatis Mapper:
@Mapper
public interface MessageMapper {
@Select("select * from message")
Collection<Message> selectAll();
}
UPDATE
It feels like I'm having some fundamental knowledge based mistake. Probably managing external libraries.
Here's maven pom.xml. Looks kind of overloaded, I faced a lot of errors managing different spring-boot packages. Starter for autoconfiguration included.
pom.xml
Here's the project structure:
UPDATE #2
I'm sure DB connection is working well, I'm able to track changes in MySQL Workbench while Spring Boot is executing schema.sql and data.sql. But somehow, MyBatis mapper methods throw NullPointerException and page proceeds with exit code 500. Seems like they can't connect.

new MessageService();this creates an instance outside the control of Spring and no auto wiring will happen. You need to inject theMessageServiceinto the controller as well. - M. Deinum@Autowired private MessageService messageServiceit gets underlined by IDEA and doesn't compile. - Zhannur DiyasMessageServicewith@Serviceelse it will not be detected. Also I doubt that it won't compile I suspect your IDE is telling you thatMessageServicecannot be auto wired. - M. DeinumCould not autowire: No beans of "MessageMapper" found.- Zhannur Diyas