안녕하세요! 게시글에 나와있는 것처럼 pom.xml 과 root-context.xml 등 설정을 따라했는데, 계속해서 500에러가 발생하고 jdbc와 연결이 되지 않았다는 듯한 에러가 발생하여 곤란을 겪고 있습니다 ㅠㅠ 소스가 길어지겠지만 어느 부분에 오류가 있는지 봐주시면 감사하겠습니다.... 진도를 전혀 나가지 못하고 있습니다 ㅜㅜ
에러문구는 다음과 같습니다
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.company.mapper.TestMapper.getList
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:866)
javax.servlet.http.HttpServlet.service(HttpServlet.java:655)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851)
javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
pom.xml (사정상 postgresSQL 9.5를 사용합니다)
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
<scope>provided</scope>
</dependency>
<!-- postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.0.0</version>
</dependency>
<!-- MyBatis 3.4 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.1</version>
</dependency>
<!-- MyBatis-Spring 1.3-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.0</version>
</dependency>
<!-- Spring-JDBC -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
root-context.xml
<!-- properties -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:/jdbc.properties" />
<property name="fileEncoding" value="UTF-8" />
</bean>
<!-- JDBC-PostgreSQL -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<!-- MyBatis-Spring -->
<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:/sqlmap/*.xml" />
-->
</bean>
<mybatis-spring:scan base-package="com.company.mapper"/>
</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 type="com.company.command.TestVO" alias="TestVO"/>
</typeAliases>
</configuration>
jdbc.properties
jdbc.driverClassName=org.postgresql.Driver
jdbc.url=jdbc:postgresql://localhost:5432/postgres
jdbc.username=postgres
jdbc.password=
# ID, PW
TestController.java
@Controller
public class TestController {
@Autowired
private TestService testService;
@RequestMapping(value = "/test/testView")
public void test(Model model) {
ArrayList<TestVO> list = testService.getList();
model.addAttribute("list", list);
} }
TestService.java
public interface TestService {
public ArrayList<TestVO> getList();
}
TestServiceImpl.java
@Service
public class TestServiceImpl implements TestService{
@Autowired
private TestMapper testMapper;
@Override
public ArrayList<TestVO> getList() {
return testMapper.getList();
} }
TestMapper.java
public interface TestMapper {
// @Select("select * from users")
public ArrayList<TestVO> getList();
}
TestMapper.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="com.company.mapper.TestMapper">
<select id="getList" resultType="TestVO">
select * from users
</select>
</mapper>
testView.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<p>db 연결 확인</p>
<c:forEach var="vo" items="${list}">
<p> ID is ${vo.id} </p>
</c:forEach>
</body>
</html>
sehongpark님의 답변
## TestMapper 객체와
TestMapper.xml 연동이 잘 안된 듯 합니다.
제 게시글에서 소개하는
어노테이션 방식으로 먼저 동작하는지 먼저 확인하시고,
mybatis 공식 문서를 참고해 설정을 완료해보세요.
- https://mybatis.org/spring/ko/factorybean.html
- https://mybatis.org/spring/ko/mappers.html