I'm studying spring mvc - mybatis application using spring 4.3.18.RELEASE, mybatis-spring 2.0.2 (also, IDE : intelliJ)
I checked the namespace, the location of the mapper, etc., but I couldn't solve the error. I don't know what I'm missing. I'd really appreciate it if you could help me.
I got the following error.
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): org.example.HelloService.HelloService.getHello
datasourceContext.xml
...
<bean id="SqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:/mybatis-config.xml"/>
<property name="mapperLocations" value="classpath:/mappers/*.xml"/>
</bean>
<mybatis-spring:scan base-package="org.example"/>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate" destroy-method="clearCache">
<constructor-arg ref="SqlSessionFactory"/>
</bean>
</beans>
mybatis-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd" >
<configuration>
<typeAliases>
<typeAlias alias="HelloDto" type="org.example.HelloDto.HelloDto"/>
</typeAliases>
</configuration>
helloMapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.example.HelloMapper.HelloMapper">
<select id="selectHello" resultType="org.example.HelloDto.HelloDto">
select * from temp.temp_tbl
</select>
</mapper>
HelloController.java
package org.example.HelloController;
import org.example.HelloDto.HelloDto;
import org.example.HelloService.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.List;
@Controller
public class HelloController {
@Autowired
private HelloService helloService;
@GetMapping("/hello")
public String hello(Model model){
List<HelloDto> helloList = helloService.getHello();
model.addAttribute("helloList", helloList);
return "hello";
}
}
HelloService.java
package org.example.HelloService;
import org.example.HelloDto.HelloDto;
import java.util.List;
public interface HelloService {
List<HelloDto> getHello();
}
HelloServiceImpl.java
package org.example.HelloService.impl;
import org.example.HelloDto.HelloDto;
import org.example.HelloMapper.HelloMapper;
import org.example.HelloService.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class HelloServiceImpl implements HelloService {
@Autowired
private HelloMapper helloMapper;
@Override
public List<HelloDto> getHello() {
return helloMapper.selectHello();
}
}
HelloDto
package org.example.HelloDto;
import org.springframework.stereotype.Component;
public class HelloDto {
private String id;
private String password;
public HelloDto(String id, String password) {
this.id = id;
this.password = password;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public String toString() {
return "HelloDto{" +
"id='" + id + '\'' +
", password='" + password + '\'' +
'}';
}
}
HelloMapper.java
package org.example.HelloMapper;
import org.apache.ibatis.annotations.Mapper;
import org.example.HelloDto.HelloDto;
import java.util.List;
@Mapper
public interface HelloMapper {
List<HelloDto> selectHello();
}
It's a whole file structure.enter image description here