mybatis上的奇怪之处:Mapped Statements集合不包含值

时间:2014-12-03 03:33:22

标签: junit mybatis

当我使用junit4在mybatis + spring上测试代码时,发生了一个非常奇怪的问题。

可以正常运行 - 码头环境吗?

但是当它在junit上运行时,会出现错误。

BaseTest.java

package com.test.spring.action;

import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;

@ContextConfiguration(
        {"classpath:application-context.xml"
})
@RunWith(SpringJUnit4ClassRunner.class)
@TransactionConfiguration(transactionManager="transactionManager",defaultRollback=true)
public class BaseTest extends AbstractTransactionalJUnit4SpringContextTests{

}

UserAction.java

package com.test.spring.action;

import org.apache.log4j.Logger;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.test.spring.service.UserService;
@Component
public class UserAction extends BaseTest{

    Logger logger = Logger.getLogger(BaseTest.class);
    @Autowired
    UserService userService;

    @Test
    public void testInsertAccount() {
        userService.getAll();

    }
}

下面的xml配置:

应用context.xml中

....
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
       <property name="dataSource" ref="dataSource" />
       <property name="typeAliasesPackage" value="com.test.spring.entity"/>
        <!-- mapper和resultmap配置路径 -->
        <property name="mapperLocations">
            <list>
                <value>classpath:com/test/spring/mapper/*-mapper.xml</value>
            </list>
        </property>
    </bean> 
 .....

用户mapper.xml

<mapper namespace="com.test.spring.mapper.UserMapper">

    <select id="getAll" resultType="user">
        <![CDATA[
            select * from user
        ]]>
    </select>  ...others selects

有人能帮我弄清楚它有什么问题吗?

如果你愿意,我可以提供更多细节。

感谢。

0 个答案:

没有答案