mybatis 测试类junit报错,如何解决 mybatis 测试类junit报错,如何解决

package com.jiyun.mybaits.test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import com.jiyun.mybaits.pojo.User;

public class JunitTest {

@Test
private void test1() throws IOException {
    // TODO Auto-generated method stub
    String resource = "SqlMapConfig.xml";
    InputStream inputStream = Resources.getResourceAsStream(resource);
    SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
    SqlSession openSession = sessionFactory.openSession();
    List<User> userList = openSession.selectList("test.selectAllUser");
    for (User user : userList) {
        System.out.println(user.getUsername() + "--" + user.getPassword() + "--" + user.getSex());
    }
    openSession.close();
}

图片说明

1个回答

方法写成public试试,,,,private,,,怎么能找得到

对你有帮助给个采纳......................^.^

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
mybatis项目单元测试,junit报错:找不到测试类

刚开始学mybatis,Junit运行出现了找不到测试类的情况 这是报错信息: ![图片说明](https://img-ask.csdn.net/upload/201911/21/1574303586_534941.png) 这个是代码: ![图片说明](https://img-ask.csdn.net/upload/201911/21/1574303753_113211.png) ![图片说明](https://img-ask.csdn.net/upload/201911/21/1574303786_311038.png) ![图片说明](https://img-ask.csdn.net/upload/201911/21/1574303829_922250.png) 还有项目的一些包: ![图片说明](https://img-ask.csdn.net/upload/201911/21/1574303879_11919.png) 之前也试过在编译器你改默认的构建,但是没什么效果,也看了jdk1.8和mybatis3应该不冲突。求问大佬们是什么问题?

mybatis测试类单表查询报错

package logger.jack.mybatis.authority.mapper; import jack.mybatis.authority.mapper.UserMapper; import jack.mybatis.authority.model.SysUser; import java.io.Reader; import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.junit.BeforeClass; import org.junit.Test; public class UserMapperTest { static SqlSessionFactory sqlSessionFactory; @BeforeClass public static void init() { try { Reader reader = Resources.getResourceAsReader("mybatis-config.xml"); sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); reader.close(); } catch (Exception e) { e.printStackTrace(); } } @Test public void testSelectAll() { SqlSession sqlSession = sqlSessionFactory.openSession(); try { UserMapper userMapper = sqlSession.getMapper(UserMapper.class); SysUser user = userMapper.selectUserById(1L); System.out.println(user.getId()+","+user.getUserName()); }finally { sqlSession.close(); } } } ``` <?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="jack.mybatis.authority.mapper.UserMapper" > <resultMap type="SysUser" id="userMap"> <id property="id" column="id"/> <result property="userName" column="user_name"/> <result property="userPassword" column= "user_password"/> <result property="userEmail" column="user_email"/> <result property="userInfo" column="user_info"/> <result property="headImg" column="head_img" jdbcType="BLOB"/> <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/> </resultMap> <select id="selectUserById" resultMap="userMap" parameterType="Long"> select * from sys_user where id=#{id} </select> </mapper> ``` package jack.mybatis.authority.mapper; import jack.mybatis.authority.model.SysUser; public interface UserMapper { SysUser selectUserById(Long id); } # ```控制台报错内容**** ```org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession. ### The error may exist in jack/mybatis/authority/mapper/UserMapper.xml ### The error occurred while processing mapper_resultMap[userMap] ### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'SysUser'. Cause: java.lang.ClassNotFoundException: Cannot find class: SysUser at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:54) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:38) at logger.jack.mybatis.authority.mapper.UserMapperTest.init(UserMapperTest.java:27) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'SysUser'. Cause: java.lang.ClassNotFoundException: Cannot find class: SysUser at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:109) at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:92) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:52) ... 17 more Caused by: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'SysUser'. Cause: java.lang.ClassNotFoundException: Cannot find class: SysUser at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:120) at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:92) at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:322) at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:107) ... 19 more Caused by: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'SysUser'. Cause: java.lang.ClassNotFoundException: Cannot find class: SysUser at org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:103) at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:264) at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:251) at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElements(XMLMapperBuilder.java:243) at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:116) ... 22 more Caused by: org.apache.ibatis.type.TypeException: Could not resolve type alias 'SysUser'. Cause: java.lang.ClassNotFoundException: Cannot find class: SysUser at org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:117) at org.apache.ibatis.builder.BaseBuilder.resolveAlias(BaseBuilder.java:130) at org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:101) ... 26 more Caused by: java.lang.ClassNotFoundException: Cannot find class: SysUser at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:190) at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:89) at org.apache.ibatis.io.Resources.classForName(Resources.java:256) at org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:113) ... 28 more ``` ```![图片说明](https://img-ask.csdn.net/upload/202004/29/1588093769_578587.png) ![图片说明](https://img-ask.csdn.net/upload/202004/29/1588093778_148241.png) ![图片说明](https://img-ask.csdn.net/upload/202004/29/1588093877_705194.png)

maven-Spring项目,junit报错ClassNotFoundException

(引用的第三方包找不到,引用的其它模块的class也找不到),但是项目使用jetty启动是正常的。之前是可以的,初步估计是eclipse的配置问题或者maven building但是一致没解决。 哪位大神遇见过有经验的话分享一下。 备注:之前这个测试类是可以正常运行的,新版本重写从SVN check一份,可能修改了eclipse配置,junit就无法正常运行了。 1、关于引用第三方oracle驱动jar包,报错classnotFoundException已经解决,我在其它同事电脑上测试是正常的,然后将他eclipse的.metadata文件夹复制到我的项目解决了。因为之前根据自己的喜好调整过eclipse。所以可能动了哪里了。 2、很感谢各位的回答,您们的回答已经覆盖了大多数ClassNotFoundException的原因,可以留着以后参考。

spring4+mybatis3整合 junit测试的问题

applicationContext.xml <!-- <context:property-placeholder location="classpath:jdbc.properties"/> --> <context:component-scan base-package="com"/> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:jdbc.properties</value> </list> </property> </bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${driverClassName}"/> <property name="url" value="${url}"/> <property name="username" value="${username}"/> <property name="password" value="${password}"/> </bean> <!-- sessionFactory 配置--> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="mapperLocations" value="classpath:com/zhikun/bean/basexml/*.xml"/> <property name="configLocation" value="classpath:SqlMapConfig.xml"/> </bean> <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate" > <constructor-arg index="0" ref="sqlSessionFactory" /> <constructor-arg index="1" value="BATCH" /> </bean> <bean id="baseDao" class="com.zhikun.dao.base.BaseDaoImpl2"> <property name="sqlSessionTemplate" ref="sqlSessionTemplate"></property> </bean> <tx:annotation-driven /> mybatis.xml <configuration> <typeAliases> <typeAlias alias="Person" type="com.zhikun.bean.Person"/> </typeAliases> </configuration> basedao public class BaseDaoImpl2<T extends Serializable> implements IBaseDao<T> { public SqlSessionTemplate sqlSessionTemplate; public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) { this.sqlSessionTemplate = sqlSessionTemplate; } @Override public int save(T t) { return sqlSessionTemplate.insert("com.zhikun.bean.Person.save", t); } Test类 @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"classpath:applicationContext.xml"}) public class TestDao extends AbstractJUnit4SpringContextTests { @Test public void save(){ PersonDao persondao = new PersonDao(); Person p = new Person(); p.setName("zhouhang"); p.setNickname("周航"); p.setSeqce(123L); p.setBirthday(new Date()); //sqlSessionTemplate.insert("com.zhikun.bean.Person.save", p); persondao.save(p); } } }

spring/mybatis整合,junit测试报BeanCreationException

<div class="iteye-blog-content-contain" style="font-size: 14px;"> <p>昨天想整合下springmvc和mybatis,用junit写了个测试,测试过程中,mybatis的mapper无法注入,报BeanCreationException,相关信息大家看下,帮小弟解决下</p> <p> </p> <p><span style="color: #993300;">1 错误堆栈信息</span></p> <p>    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.hft.dal.mapper.AccountMapperTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.hft.dal.mapper.AccountMapper com.hft.dal.mapper.AccountMapperTest.accountMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.hft.dal.mapper.AccountMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}</p> <p> </p> <p><span style="color: #993300;">2 applicationContext.xml</span></p> <p><span style="color: #333333;"><br>    &lt;context:component-scan base-package="com.hft" /&gt;<br>    &lt;context:annotation-config /&gt;<br>    &lt;tx:annotation-driven /&gt;<br>    &lt;bean id="dataSource"<br>        class="org.springframework.jdbc.datasource.DriverManagerDataSource"<br>        destroy-method="close"&gt;<br>        &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;<br>        &lt;property name="url" value="jdbc:mysql://127.0.0.1:3306/test" /&gt;<br>        &lt;property name="username" value="root" /&gt;<br>        &lt;property name="password" value="root" /&gt;<br>    &lt;/bean&gt;<br>    &lt;bean id="transactionManager"<br>        class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt;<br>        &lt;property name="dataSource" ref="dataSource" /&gt;<br>    &lt;/bean&gt;<br>    &lt;bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"&gt;<br>        &lt;property name="dataSource" ref="dataSource" /&gt;<br>        &lt;property name="mapperLocations"&gt;<br>            &lt;list&gt;<br>                &lt;value&gt;classpath*:com/hft/dal/mapper/*Mapper.xml&lt;/value&gt;<br>            &lt;/list&gt;<br>        &lt;/property&gt;<br>    &lt;/bean&gt;<br>    &lt;bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"&gt;<br>        &lt;property name="basePackage" value="com.hft.dal.mapper" /&gt;<br>        &lt;property name="markerInterface" value="com.hft.dal.mapper.MarkerInterfaceMapper" /&gt;<br>    &lt;/bean&gt;</span></p> <p> </p> <p><span style="color: #993300;">3 AccountMapper类,MarkerInterfaceMapper是个空接口</span></p> <p><span style="color: #333333;">public interface AccountMapper extends MarkerInterfaceMapper {<br>    public List&lt;Account&gt; getAllAccount();<br>    public void addAccount(Account account);<br>}<br></span></p> <p><span style="color: #993300;">4 junittest类</span></p> <p><span style="color: #333333;">@RunWith(SpringJUnit4ClassRunner.class)<br>@ContextConfiguration(locations={"classpath*:applicationContext.xml"})<br>public class AccountMapperTest extends AbstractJUnit4SpringContextTests{<br>    @Autowired<br>    private AccountMapper accountMapper;<br>    @Test<br>    public void testGetAllAccount() {<br>        System.out.println(accountMapper.getAllAccount().size());<br>  }</span></p> <p> </p> <p><span style="color: #993300;">5 所引入的的包</span></p> <p><span style="color: #993300;"><br><img src="http://dl2.iteye.com/upload/attachment/0086/5155/b987f220-1b71-30b8-88d2-e63f8bff6faf.png" alt=""><br> <br>6 项目目录结构<br><img src="http://dl2.iteye.com/upload/attachment/0086/5168/5ffcffac-6c9b-390c-8b39-5ff0bfec6c12.png" alt=""><br> <br> <br> </span></p> </div>

搭建SSM框架进行JUnit测试spring和mybatis整合

log4j:WARN No such property [converssionPattern] in org.apache.log4j.PatternLayout. log4j:WARN No such property [macFileSize] in org.apache.log4j.RollingFileAppender. [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from class path resource [spring-mybatis.xml] [org.springframework.test.context.TestContextManager] - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@10587f1] to prepare test instance [org.zsl.testmybatis.TestMybatis@176b067] java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99) at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:101) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75) at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:319) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:212) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:232) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:175) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 11 in XML document from class path resource [spring-mybatis.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 11; columnNumber: 88; cvc-elt.1: 找不到元素 'beans' 的声明。 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:335) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:251) at org.springframework.test.context.support.AbstractGenericContextLoader.loadBeanDefinitions(AbstractGenericContextLoader.java:235) at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:118) at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100) at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:250) at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64) at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91) ... 25 more Caused by: org.xml.sax.SAXParseException; lineNumber: 11; columnNumber: 88; cvc-elt.1: 找不到元素 'beans' 的声明。 at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1906) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:746) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:379) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:605) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3138) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:880) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141) at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:243) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:348) at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:76) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.java:428) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390) ... 38 more

mybatis spring 整合 junit测试。 事务不起作用,不提交。删除无效???

applicationContext.xml 中的数据库和 sessionFactory以及事务配置 Xml代码 <bean id="bssDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <!-- Connection Info --> <property name="driverClassName" value="${bss.jdbc.driver}" /> <property name="url" value="${bss.jdbc.url}" /> <property name="username" value="${bss.jdbc.username}" /> <property name="password" value="${bss.jdbc.password}" /> <!-- Connection Pooling Info --> <property name="maxActive" value="${bss.dbcp.maxActive}" /> <property name="maxIdle" value="${bss.dbcp.maxIdle}" /> <property name="defaultAutoCommit" value="false" /> <!-- 连接Idle一个小时后超时 --> <property name="timeBetweenEvictionRunsMillis" value="3600000" /> <property name="minEvictableIdleTimeMillis" value="3600000" /> <property name="testOnBorrow" value="true" /> <property name="testWhileIdle" value="true" /> <property name="validationQuery" value="${bss.dbcp.validationQuery}" /> </bean> <!-- MyBatis配置 --> <bean id="bssSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="bssDataSource" /> <!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 别名 --> <property name="typeAliasesPackage" value="com.jxnc56.bss.entity" /> <!-- 显式指定Mapper文件位置 --> <property name="mapperLocations" > <list> <value> classpath:config/mybatis/sqlmap/bss/**/*.xml </value> </list> </property> </bean> <!-- 扫描basePackage下所有以@MyBatisRepository标识的 接口--> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.jxnc56.bss" /> <property name="annotationClass" value="com.jxnc56.bss.dao.MyBatisRepository"/> </bean> <!-- 事务管理,@Transactional("tmBss") --> <bean id="tmBss" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="bssDataSource"></property> <qualifier type="org.springframework.beans.factory.annotation.Qualifier" value="tmBss" /> </bean> <!-- 使用annotation定义数据库事务,这样可以在类或方法中直接使用@Transactional注解来声明事务 --> <tx:annotation-driven transaction-manager="tmBss" proxy-target-class="true" /> java TEST: Java代码 @Transactional("tmBss") public class ProductServiceTest extends SpringTransactionalTestCase { @Autowired private ProductDao pDao; @Test public void deleteTest (){ pDao.delete(4); Product product = new Product(); product.setId(4); System.out.println("-------------------------------------------->"+Arrays.toString(pDao.select(product).toArray())); } } 其中ProductDao 是被@MyBatisRepository标示的接口 log: 2013-06-07 09:40:57 107 - org.mybatis.spring.transaction.SpringManagedTransaction -915 [main] DEBUG org.mybatis.spring.transaction.SpringManagedTransaction - JDBC Connection [jdbc:mysql://localhost/nrcompany?useUnicode=true&characterEncoding=utf-8, UserName=root@localhost, MySQL-AB JDBC Driver] will be managed by Spring 2013-06-07 09:40:57 110 - com.jxnc56.bss.dao.ProductDao.delete -918 [main] DEBUG com.jxnc56.bss.dao.ProductDao.delete - ooo Using Connection [jdbc:mysql://localhost/nrcompany?useUnicode=true&characterEncoding=utf-8, UserName=root@localhost, MySQL-AB JDBC Driver] 2013-06-07 09:40:57 115 - com.jxnc56.bss.dao.ProductDao.delete -923 [main] DEBUG com.jxnc56.bss.dao.ProductDao.delete - ==> Preparing: delete from product where id=? 2013-06-07 09:40:57 140 - com.jxnc56.bss.dao.ProductDao.delete -948 [main] DEBUG com.jxnc56.bss.dao.ProductDao.delete - ==> Parameters: 4(Integer) 2013-06-07 09:40:57 142 - org.mybatis.spring.SqlSessionUtils -950 [main] DEBUG org.mybatis.spring.SqlSessionUtils - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3a9d95] 2013-06-07 09:40:57 142 - org.mybatis.spring.SqlSessionUtils -950 [main] DEBUG org.mybatis.spring.SqlSessionUtils - Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3a9d95] from current transaction

mybatis测试时空指针异常

``` public class UserDaoImplTest { private SqlSessionFactory sqlSessionFactory; @Before public void setUp() throws Exception{ String resource = "SqlMapConfig.xml"; InputStream inputStream = org.apache.ibatis.io.Resources.getResourceAsStream(resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); } @Test //测试方法 public void testFindUserById() throws Exception { UserDao userDao = new UserDaoImpl(sqlSessionFactory); User user = userDao.findUserById(1);//错误在这 System.out.println(user); } } ``` public class UserDaoImpl implements UserDao{ private SqlSessionFactory sqlSessionFactory; public UserDaoImpl(SqlSessionFactory sqlSessionFactory) { this.sqlSessionFactory = sqlSessionFactory; } @Override public User findUserById(int id) throws Exception { SqlSession sqlSession = sqlSessionFactory.openSession(); User user = sqlSession.selectOne("test.findUserById",1); sqlSession.close(); return user; } ``` ``` 新手求指点下怎么解决。。

SpringBoot Junit测试问题

请教下大神: 在普通代码中加上注解后可以直接完成对象注入 在test包下建立专门的测试类时,对象无法直接注入,需在注解后配置 但是加上配置集成的mybatis的mapper文件也无法完成注入。

运行Junit的test方法时,报这个错怎么办.谢谢

七月 21, 2017 7:19:23 下午 org.springframework.context.support.AbstractApplicationContext prepareRefresh 信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@68f7aae2: startup date [Fri Jul 21 19:19:23 CST 2017]; root of context hierarchy 七月 21, 2017 7:19:23 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 信息: Loading XML bean definitions from class path resource [spring-mybatis.xml] 七月 21, 2017 7:19:24 下午 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons 信息: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3fee9989: defining beans [dbcp,ssf,mapperScanner]; root of factory hierarchy

Spring+Mybatis 向oracle的Clob字段插入报错 在线等!

项目是使用Spring+SpringMVC+Mybatis构建的,使用JUnit4写了个测试类直接调用serivice层的update方法是可以成功插入,但是在Controler层调用service中的update方法就报错,下o: Cause: java.sql.SQLException: 数据大小超出此类型的最大值: 35845 ; uncategorized SQLException for SQL []; SQL state [null]; error code [17070]; 数据大小超出此类型的最大值: 35845; nested exception is java.sql.SQLException: 数据大小超出此类型的最大值: 35845 org.springframework.jdbc.UncategorizedSQLException: ### Error updating database. Cause: java.sql.SQLException: 数据大小超出此类型的最大值: 35845 ### The error may involve com.ffcs.cq.repository.mybatis.work.BugMybatisDao.update-Inline ### The error occurred while setting parameter DETAIL=? WHERE DBID = ? ### Cause: java.sql.SQLException: 数据大小超出此类型的最大值: 3650 ; uncategorized SQLException for SQL []; SQL state [null]; error code [17070]; 数据大小超出此类型的最大值: 3650; nested exception is java.sql.SQLException: 数据大小超出此类型的最大值: 3650 at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:84) ~[spring-jdbc-4.0.5.RELEASE.jar:4.0.5.RELEASE] at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-4.0.5.RELEASE.jar:4.0.5.RELEASE] at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-4.0.5.RELEASE.jar:4.0.5.RELEASE] at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73) ~[mybatis-spring-1.2.2.jar:1.2.2] at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371) ~[mybatis-spring-1.2.2.jar:1.2.2] at com.sun.proxy.$Proxy18.update(Unknown Source) ~[na:na] at org.mybatis.spring.SqlSessionTemplate.update(SqlSessionTemplate.java:254) ~[mybatis-spring-1.2.2.jar:1.2.2] at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:54) ~[mybatis-3.2.8.jar:3.2.8] at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52) ~[mybatis-3.2.8.jar:3.2.8] at com.sun.proxy.$Proxy35.update(Unknown Source) ~[na:na] at com.ffcs.cq.service.work.BugService.modify(BugService.java:395) ~[BugService.class:na] at com.ffcs.cq.service.work.BugService$$FastClassBySpringCGLIB$$83194116.invoke(<generated>) ~[spring-core-4.0.5.RELEASE.jar:na] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.0.5.RELEASE.jar:4.0.5.RELEASE] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:708) ~[spring-aop-4.0.5.RELEASE.jar:4.0.5.RELEASE]

JUnit单元测试的时候总是openSession()报错????求解?????

JUnit单元测试的时候总是openSession()报错 ![图片说明](https://img-ask.csdn.net/upload/201708/03/1501750971_346629.png) ![图片说明](https://img-ask.csdn.net/upload/201708/03/1501751013_307114.png)

spring、mybatis整合遇到的问题

单元测试报错: Invalid bound statement (not found): com.cn.mysite .mybatisdemo.dao.IUserDao.queryUserList 下面相关代码和配置文件: 1、先放上结构图: ![图片说明](https://img-ask.csdn.net/upload/201706/13/1497331060_144583.png) 2、spring-mybatis.xml配置文件代码如下: <!-- 自动扫描 --> <context:component-scan base-package="com.cn.mysite.mybatisdemo" /> <!-- jdbc配置文件导入 --> <context:property-placeholder location="classpath:jdbc.properties"/> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <!-- 连接池配置 --> <property name="driverClassName" value="${database.driverClassName}"/> <property name="url" value="${database.url}"/> <property name="username" value="${database.username}"/> <property name="password" value="${database.password}"/> <!-- 初始化连接大小 --> <property name="initialSize" value="0"></property> <!-- 连接池最大数量 --> <property name="maxActive" value="20"></property> <!-- 连接池最大空闲 --> <property name="maxIdle" value="20"></property> <!-- 连接池最小空闲 --> <property name="minIdle" value="1"></property> <!-- 获取连接最大等待时间 --> <property name="maxWait" value="30000"></property> </bean> <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="mapperLocations" value="classpath*:com/cn/mysite/mybatisdemo/mapping/*.xml"/> </bean> <!-- DAO接口所在包名,Spring会自动查找其下的类 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.cn.mysite.mybatisdemo.dao" /> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/> </bean> ``` ``` 3、IUserDao接口代码: public interface IUserDao { List<User> queryUserList(); } ``` 4、mapping中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.cn.mysite.mybatisdemo.dao.IUserDao" > <resultMap type ="com.cn.mysite.mybatisdemo.model.User" id="usermap"> <result property ="id" column="id" /> <result property ="name" column="name" /> <result property ="age" column="age" /> <result property ="email" column="email" /> <result property ="address" column="address" /> </resultMap> <!-- 查询所有用户记录 --> <select id ="queryUserList" resultMap= "usermap"> select * from person </select > </mapper> 5、测试类: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"classpath:spring-mybatis.xml"}) public class MybatisTest { @Resource private IUserDao dao; @Test public void test() { dao.queryUserList(); System.out.println("Hello World!"); } } 单元测试就开始报错,请大家帮看一下是哪一步出错了,感觉好奇怪啊,实在查不出问题了

mybatis单元测试空指针

![![![图片说明](https://img-ask.csdn.net/upload/201610/10/1476068010_542255.png)图片说明](https://img-ask.csdn.net/upload/201610/10/1476068030_892503.png)图片说明](https://img-ask.csdn.net/upload/201610/10/1476068022_317570.png) 总是空指针异常 查不到数据库

mybatis spring 整合 junit测试。 事务不起作用,不提交。插入无效???

applicationContext.xml 中的数据库和 sessionFactory以及事务配置 [code="xml"] <bean id="bssDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <!-- Connection Info --> <property name="driverClassName" value="${bss.jdbc.driver}" /> <property name="url" value="${bss.jdbc.url}" /> <property name="username" value="${bss.jdbc.username}" /> <property name="password" value="${bss.jdbc.password}" /> <!-- Connection Pooling Info --> <property name="maxActive" value="${bss.dbcp.maxActive}" /> <property name="maxIdle" value="${bss.dbcp.maxIdle}" /> <property name="defaultAutoCommit" value="false" /> <!-- 连接Idle一个小时后超时 --> <property name="timeBetweenEvictionRunsMillis" value="3600000" /> <property name="minEvictableIdleTimeMillis" value="3600000" /> <property name="testOnBorrow" value="true" /> <property name="testWhileIdle" value="true" /> <property name="validationQuery" value="${bss.dbcp.validationQuery}" /> </bean> <!-- MyBatis配置 --> <bean id="bssSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="bssDataSource" /> <!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 别名 --> <property name="typeAliasesPackage" value="com.jxnc56.bss.entity" /> <!-- 显式指定Mapper文件位置 --> <property name="mapperLocations" > <list> <value> classpath:config/mybatis/sqlmap/bss/**/*.xml </value> </list> </property> </bean> <!-- 扫描basePackage下所有以@MyBatisRepository标识的 接口--> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.jxnc56.bss" /> <property name="annotationClass" value="com.jxnc56.bss.dao.MyBatisRepository"/> </bean> <!-- 事务管理,@Transactional("tmBss") --> <bean id="tmBss" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="bssDataSource"></property> <qualifier type="org.springframework.beans.factory.annotation.Qualifier" value="tmBss" /> </bean> <!-- 使用annotation定义数据库事务,这样可以在类或方法中直接使用@Transactional注解来声明事务 --> <tx:annotation-driven transaction-manager="tmBss" proxy-target-class="true" /> [/code] java TEST: [code="java"] @Transactional("tmBss") public class ProductServiceTest extends SpringTransactionalTestCase { @Autowired private ProductDao pDao; @Test public void deleteTest (){ pDao.delete(4); Product product = new Product(); product.setId(4); System.out.println("-------------------------------------------->"+Arrays.toString(pDao.select(product).toArray())); } } [/code] 其中ProductDao 是被@MyBatisRepository标示的接口 log: 2013-06-07 09:40:57 107 - org.mybatis.spring.transaction.SpringManagedTransaction -915 [main] DEBUG org.mybatis.spring.transaction.SpringManagedTransaction - JDBC Connection [jdbc:mysql://localhost/nrcompany?useUnicode=true&characterEncoding=utf-8, UserName=root@localhost, MySQL-AB JDBC Driver] will be managed by Spring 2013-06-07 09:40:57 110 - com.jxnc56.bss.dao.ProductDao.delete -918 [main] DEBUG com.jxnc56.bss.dao.ProductDao.delete - ooo Using Connection [jdbc:mysql://localhost/nrcompany?useUnicode=true&characterEncoding=utf-8, UserName=root@localhost, MySQL-AB JDBC Driver] 2013-06-07 09:40:57 115 - com.jxnc56.bss.dao.ProductDao.delete -923 [main] DEBUG com.jxnc56.bss.dao.ProductDao.delete - ==> Preparing: delete from product where id=? 2013-06-07 09:40:57 140 - com.jxnc56.bss.dao.ProductDao.delete -948 [main] DEBUG com.jxnc56.bss.dao.ProductDao.delete - ==> Parameters: 4(Integer) 2013-06-07 09:40:57 142 - org.mybatis.spring.SqlSessionUtils -950 [main] DEBUG org.mybatis.spring.SqlSessionUtils - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3a9d95] 2013-06-07 09:40:57 142 - org.mybatis.spring.SqlSessionUtils -950 [main] DEBUG org.mybatis.spring.SqlSessionUtils - Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3a9d95] from current transaction

springboot+mybatis(xml模式) 项目 单元测试 报错。

2017-09-01 17:35:21.034 INFO 11212 --- [ main] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} inited org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.lxhw.module.jbxx.dao.DjKjfCzryDao.getCzry at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:230) at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:48) at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:65) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58) at com.sun.proxy.$Proxy98.getCzry(Unknown Source) at com.lxhw.module.jbxx.service.DjKjfCzryService.getCzry(DjKjfCzryService.java:47) at com.lxhw.module.jbxx.service.DjKjfCzryService$$FastClassBySpringCGLIB$$30938009.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673) at com.lxhw.module.jbxx.service.DjKjfCzryService$$EnhancerBySpringCGLIB$$428d2624.getCzry(<generated>) at com.lxhw.module.jbxx.service.DjKjfCzryServiceTest.searchCzry(DjKjfCzryServiceTest.java:21) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) 这个是报错信息 项目运行正常,就是不能单元测试 初步估计是DjKjfCzryDao.class和DjKjfCzryDao.xml没有匹配上。但是run application是正常的,只有junit的时候有问题 是不是和引入mybais-spring-boot-starter有关系,不能自动去取配置文件了。

junit4 测试maven项目的时候报空指针异常

测试的时候报空指针异常 java.lang.NullPointerException at hcb.controller.hr.Employee.transferEmployee(Employee.java:378) at hello.TestEmployee.testTransferEmployee(TestEmployee.java:175) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at junit.framework.TestCase.runTest(TestCase.java:176) at junit.framework.TestCase.runBare(TestCase.java:141) at junit.framework.TestResult$1.protect(TestResult.java:122) at junit.framework.TestResult.runProtected(TestResult.java:142) at junit.framework.TestResult.run(TestResult.java:125) at junit.framework.TestCase.run(TestCase.java:129) at junit.framework.TestSuite.runTest(TestSuite.java:252) at junit.framework.TestSuite.run(TestSuite.java:247) at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) 测试的时候引用到其他的类就会报错 请问这是为什么? 麻烦求解释!!!!!!!!!

MyBatis的配置文件Conf.xml在单元测试时没问题,发布后就找不到了

![图片说明](https://img-ask.csdn.net/upload/201807/20/1532093280_903734.jpeg) 就是这里的conf.xml无法读入,但是junit测试时是没问题的。但一发布就出错了,如下图的报错信息 ![图片说明](https://img-ask.csdn.net/upload/201807/20/1532093426_905160.jpeg) 但明明xml是被编译进去的,输出文档为证 ![图片说明](https://img-ask.csdn.net/upload/201807/20/1532093534_993881.jpeg)

SpringBoot+MyBatis框架的项目,如何进行集成测试?

**@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest( classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT ) @DirtiesContext public class dataOpTest { private TBookController tBookController = new TBookController(); public TBookMapper tBookMapper; @Test public void testIfExistByName(){ String bk_name = "c++"; //int existCount = tBookController.ifExist(bk_name); int result = tBookMapper.existByNameAndState(bk_name); Assert.assertEquals(result, 1); } }** 以上代码,会认为tBookController是空指针,它本身是一个接口,sql实现都在xml文件里面,但是集成测试的时候怎么做?

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

你连存活到JDK8中著名的Bug都不知道,我怎么敢给你加薪

CopyOnWriteArrayList.java和ArrayList.java,这2个类的构造函数,注释中有一句话 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 public ArrayList(Collection&lt;? ...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

记录下入职中软一个月(外包华为)

我在年前从上一家公司离职,没想到过年期间疫情爆发,我也被困在家里,在家呆着的日子让人很焦躁,于是我疯狂的投简历,看面试题,希望可以进大公司去看看。 我也有幸面试了我觉得还挺大的公司的(虽然不是bat之类的大厂,但是作为一名二本计算机专业刚毕业的大学生bat那些大厂我连投简历的勇气都没有),最后选择了中软,我知道这是一家外包公司,待遇各方面甚至不如我的上一家公司,但是对我而言这可是外包华为,能...

无代码时代来临,程序员如何保住饭碗?

编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

培训班出来的人后来都怎么样了?(二)

接着上回说,培训班学习生涯结束了。后面每天就是无休止的背面试题,不是没有头脑的背,培训公司还是有方法的,现在回想当时背的面试题好像都用上了,也被问到了。回头找找面试题,当时都是打印下来天天看,天天背。 不理解呢也要背,面试造飞机,上班拧螺丝。班里的同学开始四处投简历面试了,很快就有面试成功的,刚开始一个,然后越来越多。不知道是什么原因,尝到胜利果实的童鞋,不满足于自己通过的公司,嫌薪水要少了,选择...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

6年开发经验女程序员,面试京东Java岗要求薪资28K

写在开头: 上周面试了一位女程序员,上午10::30来我们部门面试,2B哥接待了她.来看看她的简历: 个人简历 个人技能: ● 熟悉spring mvc 、spring、mybatis 等框架 ● 熟悉 redis 、rocketmq、dubbo、zookeeper、netty 、nginx、tomcat、mysql。 ● 阅读过juc 中的线程池、锁的源...

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

SpringBoot系列之Redis缓存使用详细教程

Spring的缓存抽象 Spring从3.1开始定义了一系列抽象接口来统一不同的缓存技术;并支持使用Java Caching(JSR-107)注解简化我们进行缓存开发。Spring Cache 只负责维护抽象层,具体的实现由你的技术选型来决定。将缓存处理和缓存技术解除耦合。 JSR107 Java Caching(JSR-107)定义了5个核心接口,分别是CachingProvider, Cach...

推荐9个能让你看一天的网站

分享的这9个保证另你意外的网站,每个都非常实用!非常干货!毫不客气的说,这些网站最少值10万块钱。 利用好这些网站,会让你各方面的技能都得到成长,不说让你走上人生巅峰,但对比现在的你,在眼界、学识、技能方面都有质的飞跃。 一、AIRPANO 传送门:https://www.airpano.com/360photo_list.php 这是一个可以躺在家里,就能环游世界的神奇网站。 世界那么大,绝大多...

大牛都会用的IDEA调试技巧!!!

导读 前天面试了一个985高校的实习生,问了他平时用什么开发工具,他想也没想的说IDEA,于是我抛砖引玉的问了一下IDEA的调试用过吧,你说说怎么设置断点...

都前后端分离了,咱就别做页面跳转了!统统 JSON 交互

文章目录1. 无状态登录1.1 什么是有状态1.2 什么是无状态1.3 如何实现无状态1.4 各自优缺点2. 登录交互2.1 前后端分离的数据交互2.2 登录成功2.3 登录失败3. 未认证处理方案4. 注销登录 这是本系列的第四篇,有小伙伴找不到之前文章,松哥给大家列一个索引出来: 挖一个大坑,Spring Security 开搞! 松哥手把手带你入门 Spring Security,别再问密...

月薪22K程序员,打卡迟到10次,收到工资短信一脸懵逼

每家公司为了保证公司员工每天的工作时间,一般都会采用上下班打卡的工作制度,这其实是一个很常见的是,本身也没有什么问题的。正所谓无规矩不成方圆,公司肯定是有公司的规矩,虽然每个员工都很不喜欢这些规矩来束缚我们,但是公司也只是为了能更好的管理员工。但是一家公司如果一成不变的使用打卡制度,而不会去变通管理,也真不一定是好事。 打卡制度特别对于销售部门来说,不但会让公司发展不起来,还很容易丢失员工。但如...

97年世界黑客编程大赛冠军作品(大小仅为16KB),惊艳世界的编程巨作

这是世界编程大赛第一名作品(97年Mekka ’97 4K Intro比赛)汇编语言所写。 整个文件只有4095个字节, 大小仅仅为16KB! 不仅实现了3D动画的效果!还有一段震撼人心的背景音乐!!! 内容无法以言语形容,实在太强大! 下面是代码,具体操作看最后! @echo off more +1 %~s0|debug e100 33 f6 bf 0 20 b5 10 f3 a5...

程序员是做全栈工程师好?还是专注一个领域好?

昨天,有位大一的同学私信我,说他要做全栈工程师。 我一听,这不害了孩子么,必须制止啊。 谁知,讲到最后,更确定了他做全栈程序员的梦想。 但凡做全栈工程师的,要么很惨,要么很牛! 但凡很牛的,绝不是一开始就是做全栈的! 全栈工程师听起来好听,但绝没有你想象的那么简单。 今天听我来给你唠,记得帮我点赞哦。 一、全栈工程师的职责 如果你学习编程的目的只是玩玩,那随意,想怎么学怎么学。...

不要再到处使用 === 了

我们知道现在的开发人员都使用 === 来代替 ==,为什么呢?我在网上看到的大多数教程都认为,要预测 JavaScript 强制转换是如何工作这太复杂了,因此建议总是使用===。这些都...

什么是a站、b站、c站、d站、e站、f站、g站、h站、i站、j站、k站、l站、m站、n站?00后的世界我不懂!

A站 AcFun弹幕视频网,简称“A站”,成立于2007年6月,取意于Anime Comic Fun,是中国大陆第一家弹幕视频网站。A站以视频为载体,逐步发展出基于原生内容二次创作的完整生态,拥有高质量互动弹幕,是中国弹幕文化的发源地;拥有大量超粘性的用户群体,产生输出了金坷垃、鬼畜全明星、我的滑板鞋、小苹果等大量网络流行文化,也是中国二次元文化的发源地。 B站 全称“哔哩哔哩(bilibili...

十个摸鱼,哦,不对,是炫酷(可以玩一整天)的网站!!!

文章目录前言正文**1、Kaspersky Cyberthreat real-time map****2、Finding Home****3、Silk – Interactive Generative Art****4、Liquid Particles 3D****5、WINDOWS93****6、Staggering Beauty****7、Ostagram图片生成器网址****8、全历史网址*...

终于,月薪过5万了!

来看几个问题想不想月薪超过5万?想不想进入公司架构组?想不想成为项目组的负责人?想不想成为spring的高手,超越99%的对手?那么本文内容是你必须要掌握的。本文主要详解bean的生命...

​能让德国人放弃现金支付​,也没谁了

在新冠疫情中,德国人越来越多地选择在超市,加油站或其他商店付款时使用非接触式付款方式。德国信贷协会Deutschen Kreditwirtschaft (DK) 的一位发言人告诉德国新...

大厂的 404 页面都长啥样?最后一个笑了...

每天浏览各大网站,难免会碰到404页面啊。你注意过404页面么?猿妹搜罗来了下面这些知名网站的404页面,以供大家欣赏,看看哪个网站更有创意: 正在上传…重新上传取消 腾讯 正在上传…重新上传取消 网易 淘宝 百度 新浪微博 正在上传…重新上传取消 新浪 京东 优酷 腾讯视频 搜...

自从喜欢上了B站这12个UP主,我越来越觉得自己是个废柴了!

不怕告诉你,我自从喜欢上了这12个UP主,哔哩哔哩成为了我手机上最耗电的软件,几乎每天都会看,可是吧,看的越多,我就越觉得自己是个废柴,唉,老天不公啊,不信你看看…… 间接性踌躇满志,持续性混吃等死,都是因为你们……但是,自己的学习力在慢慢变强,这是不容忽视的,推荐给你们! 都说B站是个宝,可是有人不会挖啊,没事,今天咱挖好的送你一箩筐,首先啊,我在B站上最喜欢看这个家伙的视频了,为啥 ,咱撇...

代码注释如此沙雕,会玩还是你们程序员!

某站后端代码被“开源”,同时刷遍全网的,还有代码里的那些神注释。 我们这才知道,原来程序员个个都是段子手;这么多年来,我们也走过了他们的无数套路… 首先,产品经理,是永远永远吐槽不完的!网友的评论也非常扎心,说看这些代码就像在阅读程序员的日记,每一页都写满了对产品经理的恨。 然后,也要发出直击灵魂的质问:你是尊贵的付费大会员吗? 这不禁让人想起之前某音乐app的穷逼Vip,果然,穷逼在哪里都是...

原来实现钉钉自动签到如此简单,每天准时上下班不是梦

本文主要介绍了如何利用现成软件快速实现钉钉自动签到功能,核心思路非常简单,甚至无任何编程基础的小白也能轻松实现定时自动打卡功能.

前端还能这么玩?(女朋友生日,用前端写了一个好玩的送给了她,高兴坏了)

前端还能这么玩?(女朋友生日,用前端写了一个好玩的送给了她,高兴坏了)

爬虫(101)爬点重口味的

小弟最近在学校无聊的很哪,浏览网页突然看到一张图片,都快流鼻血。。。然后小弟冥思苦想,得干一点有趣的事情python 爬虫库安装https://s.taobao.com/api?_ks...

讲真,这两款idea插件,能治愈你英语不好的病

时不时就有小伙伴问我,“二哥,能推荐一款 IDE 吗?”你看这话问的,现在搞 Java 的不都在用 Intellij IDEA 吗,还用得着推荐(我已经和 Eclipse 分手了)。然后小伙伴又说,“二哥,IDEA 支持中文吗?我英语不太好。”你看这话问的,搞编程的,英语不好是硬伤啊! 不过,随着 IDEA 最新版(版本号是 2020.1)的发布,英语不好的病可以彻底治愈了。为什么这么说呢?因为 ...

面试官给我挖坑:a[i][j] 和 a[j][i] 有什么区别?

点击上方“朱小厮的博客”,选择“设为星标”后台回复&#34;1024&#34;领取公众号专属资料本文以一个简单的程序开头——数组赋值:int LEN = 10000; int[][] ...

相关热词 c#树形选择 c#中类图的使用方法 c# 传参 调用exe c# 怎么定义方法 c# 修改本地时间 c#前台怎么读取资源文件 c# xml转list c#实现框选截图 m*m乘法表c# c# 乘法99表
立即提问