关于ssm项目中的报错总结

关于ssm项目中的报错总结1

20191112使用Spring的单元测试,自动注入需要的组件进行调试时出现以下报错
十一月 13, 2019 9:48:32 上午 org.springframework.test.context.support.AbstractTestContextBootstrapper getDefaultTestExecutionListenerClassNames
信息: Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
十一月 13, 2019 9:48:32 上午 org.springframework.test.context.support.AbstractTestContextBootstrapper getTestExecutionListeners
信息: Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@14acaea5, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@46d56d67, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@d8355a8, org.springframework.test.context.support.DirtiesContextTestExecutionListener@59fa1d9b, org.springframework.test.context.transaction.TransactionalTestExecutionListener@28d25987, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@4501b7af, org.springframework.test.context.event.EventPublishingTestExecutionListener@523884b2]
十一月 13, 2019 9:48:32 上午 com.mchange.v2.log.MLog
信息: MLog clients using java 1.4+ standard logging.
十一月 13, 2019 9:48:32 上午 com.mchange.v2.c3p0.C3P0Registry banner
信息: Initializing c3p0-0.9.1.1 [built 15-March-2007 01:32:31; debug? true; trace: 10]
十一月 13, 2019 9:48:33 上午 org.springframework.context.support.AbstractApplicationContext refresh
警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlSessionFactory’ defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: ‘file [E:\workspace\Crudssm\target\classes\mapper\EmployeeMapper.xml]’; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is ‘file [E:\workspace\Crudssm\target\classes\mapper\EmployeeMapper.xml]’. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.ssm.crud.dao.EmployeeMapper.selectByExample
十一月 13, 2019 9:48:33 上午 org.springframework.test.context.TestContextManager prepareTestInstance
严重: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@d8355a8] to prepare test instance [com.ssm.crud.test.MapperTest@53b7f657]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:123)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:118)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:244)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227)
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:246)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
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.ParentRunnerKaTeX parse error: Undefined control sequence: \workspace at position 1325: …urce: 'file [E:\̲w̲o̲r̲k̲s̲p̲a̲c̲e̲\Crudssm\target…doGetBeanKaTeX parse error: Undefined control sequence: \workspace at position 1692: …urce: 'file [E:\̲w̲o̲r̲k̲s̲p̲a̲c̲e̲\Crudssm\target…StrictMap.put(Configuration.java:872)
at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:844)
at org.apache.ibatis.session.Configuration.addMappedStatement(Configuration.java:668)
at org.apache.ibatis.builder.MapperBuilderAssistant.addMappedStatement(MapperBuilderAssistant.java:302)
at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:109)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:135)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:128) at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:118)
… 45 more

junit显示这个样子,经多方查证,有以下几个步骤
1、确认MySQL是否开启,未开启请打开
2、调试方法上需要加上@test
关于ssm项目中的报错总结_第1张图片
如图所示,加完之后还是会有以下报错
关于ssm项目中的报错总结_第2张图片
3、根据提示我去EmployeeMapper.xml观察代码,发现了这个
关于ssm项目中的报错总结_第3张图片
将重复的代码删除,保证EmployeeMapper.xml中没有重复的代码
4、再次调试运行,运行成功
关于ssm项目中的报错总结_第4张图片

你可能感兴趣的:(Java)