0

environments: maven ,spring 4.2.4-RELEASE , 2 modules: zscb-server zscb-common ,and zscb-server dependent on zscb-common

my web.xml core code:

  <listener>
    <listener-class>com.iidooo.core.listener.RoleResourceInitListener</listener-class>
  </listener>

i have a init listener in my module zscb-common:

RoleResourceInitListener core code:

 public void contextInitialized(ServletContextEvent arg0) {
        try {
            ServletContext sc = arg0.getServletContext();
            SqlSessionFactory sqlSessionFactory = (SqlSessionFactory) SpringUtil.getBean(sc, "sqlSessionFactory");

            SqlSession sqlSession = sqlSessionFactory.openSession(true);
            SecurityRoleMapper roleMapper = sqlSession.getMapper(SecurityRoleMapper.class);
            List<SecurityRole> roleList = roleMapper.selectAll();

            // key: roleID value:List<SecurityResource>
            Map<Integer, List<SecurityResource>> roleResourceMap = new HashMap<Integer, List<SecurityResource>>();
            for (SecurityRole item : roleList) {
                roleResourceMap.put(item.getRoleID(), item.getResourceList());
            }
            sc.setAttribute(ServletConstant.ROLE_RESOURCE_MAP, roleResourceMap);
        } catch (Exception e) {
            e.printStackTrace();
            logger.fatal(e);
        }
    }

my applicationContext.xml:

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.iidooo.core.mapper com.edo.zscb.mapper" />
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
    </bean>

i have checked my mapper.xml's namepsace:

<mapper namespace="com.iidooo.core.mapper.SecurityRoleMapper">

and when i run tomcat, error occured

Mybatis Invalid bound statement (not found)

who can save me!

junk
  • 917
  • 3
  • 11
  • 29
  • Possible duplicate of [mybatis spring mvc application, getting Invalid bound statement (not found)](https://stackoverflow.com/questions/20427210/mybatis-spring-mvc-application-getting-invalid-bound-statement-not-found) – jvwilge May 31 '17 at 19:38

2 Answers2

0

First result when googling MapperScannerConfigurer leads to the documentation stating:

The basePackage property can contain more than one package name, separated by either commas or semicolons.

while your packages are separated by a space.

blackwizard
  • 2,034
  • 1
  • 9
  • 21
0

In Mybatis if you add a mapper in a way like getMapper(YourMapper.class) or addMapper(YourMapper.class), it is necessary to leave the relative YourMapper.xml inside the same source package.

In maven it is also necessary to include the xml file(s) as resources and they must be in same place of the generated .class file.

So it would be something like this inside the <build> section of your pom.xml file:

   <build>
        ...
        <resources>
           <resource>
              <filtering>false</filtering>
              <directory>src</directory>
              <includes>
                <include>**/package_path/to/your/*.xml</include>
              </includes>
           </resource>
        </resources>
       ...
   </build>

With this configuration maven will leave .xml files in the same place as you have in your source tree.

0x3ff
  • 126
  • 1
  • 7