19
Окт
2016

BindingException при интеграции MyBatis в Spring

Ошибка в сервлете:

HTTP Status 500 - Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): by.gsu.epamlab.mapper.IUserMapper.getUser

exception org.springframework.web.util.NestedServletException: Request processing failed;

nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): by.gsu.epamlab.mapper.IUserMapper.getUser...

root cause org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): by.gsu.epamlab.mapper.IUserMapper.getUser

Сервлет:

@Controller
public class MyFirstController {
@Autowired
    private IUserMapper userMapper;

    @RequestMapping(value = "/start", method = RequestMethod.GET)
    public ModelAndView execute(Model model) {
        model.addAttribute("user", userMapper.getUser(1));//ОШИБКА ТУТ
        return new ModelAndView("start");
    }

}

Интерфейс маппера:

public interface IUserMapper {

    User getUser(int userId);

}

IUserMapper.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="by.gsu.epamlab.mapper.IUserMapper">
    <sql id="userColumns">user_id as userID, first_name as firstName, last_name as lastName, email_address as emailAddress, role_id as role, password as password</sql>
    <select id="getUser" parameterType="int" resultType="User">
        select <include refid="userColumns"/> from user where user_id = 1
    </select>
</mapper>

Бины в настройках:

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/WEB-INF/views/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <mvc:resources mapping="/resources/**" location="/resources/"/>
<context:annotation-config />
    <context:component-scan base-package="by.gsu.epamlab.controller" />
    <context:component-scan base-package="by.gsu.epamlab.service" />

    <mvc:annotation-driven />
<context:property-placeholder location="/WEB-INF/MySQLconnectionDB.properties" />

    <tx:annotation-driven transaction-manager="transactionManager" />

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${draft.db.driver}" />
        <property name="url" value="${draft.db.url}" />
        <property name="username" value="${draft.db.user}" />
        <property name="password" value="${draft.db.password}" />
    </bean>

    <bean id="transactionManager"
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="typeAliasesPackage" value="by.gsu.epamlab.entity" />
        <property name="mapperLocations" value="classpath*:by/gsu/epamlab/mapper/*.xml" />
    </bean>

    <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
        <constructor-arg index="0" ref="sqlSessionFactory" />
    </bean>

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="by.gsu.epamlab.mapper" />
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
    </bean>

Подскажите, пожалуйста, что делаю не так? Спасибо.

Структура проекта:

Структура проекта:

Дополнение к структуре проекта: доп к структуре

Источник: https://ru.stackoverflow.com/questions/580142/bindingexception-%D0%BF%D1%80%D0%B8-%D0%B8%D0%BD%D1%82%D0%B5%D0%B3%D1%80%D0%B0%D1%86%D0%B8%D0%B8-mybatis-%D0%B2-spring

Share

Тебе может это понравится...