C:\Users\peihj\.jdks\corretto-1.8.0_322\bin\java.exe -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:D:\IntelliJ IDEA 2021.1.1\lib\idea_rt.jar=53516:D:\IntelliJ IDEA 2021.1.1\bin" -Dfile.encoding=UTF-8 -classpath "D:\IntelliJ IDEA 2021.1.1\lib\idea_rt.jar;D:\IntelliJ IDEA 2021.1.1\plugins\junit\lib\junit5-rt.jar;D:\IntelliJ IDEA 2021.1.1\plugins\junit\lib\junit-rt.jar;C:\Users\peihj\.jdks\corretto-1.8.0_322\jre\lib\charsets.jar;C:\Users\peihj\.jdks\corretto-1.8.0_322\jre\lib\ext\access-bridge-64.jar;C:\Users\peihj\.jdks\corretto-1.8.0_322\jre\lib\ext\cldrdata.jar;C:\Users\peihj\.jdks\corretto-1.8.0_322\jre\lib\ext\dnsns.jar;C:\Users\peihj\.jdks\corretto-1.8.0_322\jre\lib\ext\jaccess.jar;C:\Users\peihj\.jdks\corretto-1.8.0_322\jre\lib\ext\jfxrt.jar;C:\Users\peihj\.jdks\corretto-1.8.0_322\jre\lib\ext\localedata.jar;C:\Users\peihj\.jdks\corretto-1.8.0_322\jre\lib\ext\nashorn.jar;C:\Users\peihj\.jdks\corretto-1.8.0_322\jre\lib\ext\sunec.jar;C:\Users\peihj\.jdks\corretto-1.8.0_322\jre\lib\ext\sunjce_provider.jar;C:\Users\peihj\.jdks\corretto-1.8.0_322\jre\lib\ext\sunmscapi.jar;C:\Users\peihj\.jdks\corretto-1.8.0_322\jre\lib\ext\sunpkcs11.jar;C:\Users\peihj\.jdks\corretto-1.8.0_322\jre\lib\ext\zipfs.jar;C:\Users\peihj\.jdks\corretto-1.8.0_322\jre\lib\jce.jar;C:\Users\peihj\.jdks\corretto-1.8.0_322\jre\lib\jfr.jar;C:\Users\peihj\.jdks\corretto-1.8.0_322\jre\lib\jfxswt.jar;C:\Users\peihj\.jdks\corretto-1.8.0_322\jre\lib\jsse.jar;C:\Users\peihj\.jdks\corretto-1.8.0_322\jre\lib\management-agent.jar;C:\Users\peihj\.jdks\corretto-1.8.0_322\jre\lib\resources.jar;C:\Users\peihj\.jdks\corretto-1.8.0_322\jre\lib\rt.jar;E:\javacode\springmvc006-ssm\target\test-classes;E:\javacode\springmvc006-ssm\target\classes;D:\apache-maven-3.6.1\mvn_resp\org\springframework\spring-context\5.2.5.RELEASE\spring-context-5.2.5.RELEASE.jar;D:\apache-maven-3.6.1\mvn_resp\org\springframework\spring-aop\5.2.5.RELEASE\spring-aop-5.2.5.RELEASE.jar;D:\apache-maven-3.6.1\mvn_resp\org\springframework\spring-core\5.2.5.RELEASE\spring-core-5.2.5.RELEASE.jar;D:\apache-maven-3.6.1\mvn_resp\org\springframework\spring-jcl\5.2.5.RELEASE\spring-jcl-5.2.5.RELEASE.jar;D:\apache-maven-3.6.1\mvn_resp\org\springframework\spring-expression\5.2.5.RELEASE\spring-expression-5.2.5.RELEASE.jar;D:\apache-maven-3.6.1\mvn_resp\org\springframework\spring-beans\5.2.5.RELEASE\spring-beans-5.2.5.RELEASE.jar;D:\apache-maven-3.6.1\mvn_resp\org\springframework\spring-webmvc\5.2.5.RELEASE\spring-webmvc-5.2.5.RELEASE.jar;D:\apache-maven-3.6.1\mvn_resp\org\springframework\spring-web\5.2.5.RELEASE\spring-web-5.2.5.RELEASE.jar;D:\apache-maven-3.6.1\mvn_resp\org\springframework\spring-jdbc\5.2.5.RELEASE\spring-jdbc-5.2.5.RELEASE.jar;D:\apache-maven-3.6.1\mvn_resp\org\springframework\spring-tx\5.2.5.RELEASE\spring-tx-5.2.5.RELEASE.jar;D:\apache-maven-3.6.1\mvn_resp\org\springframework\spring-aspects\5.2.5.RELEASE\spring-aspects-5.2.5.RELEASE.jar;D:\apache-maven-3.6.1\mvn_resp\org\aspectj\aspectjweaver\1.9.5\aspectjweaver-1.9.5.jar;D:\apache-maven-3.6.1\mvn_resp\org\springframework\spring-jms\5.2.5.RELEASE\spring-jms-5.2.5.RELEASE.jar;D:\apache-maven-3.6.1\mvn_resp\org\springframework\spring-messaging\5.2.5.RELEASE\spring-messaging-5.2.5.RELEASE.jar;D:\apache-maven-3.6.1\mvn_resp\org\springframework\spring-context-support\5.2.5.RELEASE\spring-context-support-5.2.5.RELEASE.jar;D:\apache-maven-3.6.1\mvn_resp\org\springframework\spring-test\5.2.5.RELEASE\spring-test-5.2.5.RELEASE.jar;D:\apache-maven-3.6.1\mvn_resp\org\mybatis\mybatis\3.5.1\mybatis-3.5.1.jar;D:\apache-maven-3.6.1\mvn_resp\org\mybatis\mybatis-spring\1.3.1\mybatis-spring-1.3.1.jar;D:\apache-maven-3.6.1\mvn_resp\com\github\miemiedev\mybatis-paginator\1.2.15\mybatis-paginator-1.2.15.jar;D:\apache-maven-3.6.1\mvn_resp\org\slf4j\slf4j-api\1.7.2\slf4j-api-1.7.2.jar;D:\apache-maven-3.6.1\mvn_resp\com\github\pagehelper\pagehelper\5.1.2\pagehelper-5.1.2.jar;D:\apache-maven-3.6.1\mvn_resp\com\github\jsqlparser\jsqlparser\1.0\jsqlparser-1.0.jar;D:\apache-maven-3.6.1\mvn_resp\mysql\mysql-connector-java\5.1.32\mysql-connector-java-5.1.32.jar;D:\apache-maven-3.6.1\mvn_resp\com\alibaba\druid\1.1.12\druid-1.1.12.jar;D:\apache-maven-3.6.1\mvn_resp\junit\junit\4.12\junit-4.12.jar;D:\apache-maven-3.6.1\mvn_resp\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;D:\apache-maven-3.6.1\mvn_resp\jstl\jstl\1.2\jstl-1.2.jar;D:\apache-maven-3.6.1\mvn_resp\javax\servlet\javax.servlet-api\3.0.1\javax.servlet-api-3.0.1.jar;D:\apache-maven-3.6.1\mvn_resp\javax\servlet\jsp-api\2.0\jsp-api-2.0.jar;D:\apache-maven-3.6.1\mvn_resp\javax\servlet\servlet-api\2.4\servlet-api-2.4.jar;D:\apache-maven-3.6.1\mvn_resp\com\fasterxml\jackson\core\jackson-databind\2.9.6\jackson-databind-2.9.6.jar;D:\apache-maven-3.6.1\mvn_resp\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;D:\apache-maven-3.6.1\mvn_resp\com\fasterxml\jackson\core\jackson-core\2.9.6\jackson-core-2.9.6.jar;D:\apache-maven-3.6.1\mvn_resp\org\json\json\20140107\json-20140107.jar;D:\apache-maven-3.6.1\mvn_resp\commons-io\commons-io\2.4\commons-io-2.4.jar;D:\apache-maven-3.6.1\mvn_resp\commons-fileupload\commons-fileupload\1.3.1\commons-fileupload-1.3.1.jar;D:\apache-maven-3.6.1\mvn_resp\org\slf4j\slf4j-log4j12\1.7.21\slf4j-log4j12-1.7.21.jar;D:\apache-maven-3.6.1\mvn_resp\log4j\log4j\1.2.17\log4j-1.2.17.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit4 test.Mytest
log4j:WARN No appenders could be found for logger (org.springframework.test.context.junit4.SpringJUnit4ClassRunner).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
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.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:190)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:221)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceimpl': Unsatisfied dependency expressed through field 'userMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userMapper' defined in file [E:\javacode\springmvc006-ssm\target\classes\com\peihj\Mapper\UserMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.apache.ibatis.session.SqlSessionFactory' available: expected single matching bean but found 2: org.mybatis.spring.SqlSessionFactoryBean#0,org.mybatis.spring.SqlSessionFactoryBean#1
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:130)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1422)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:882)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:275)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
... 24 more
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userMapper' defined in file [E:\javacode\springmvc006-ssm\target\classes\com\peihj\Mapper\UserMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.apache.ibatis.session.SqlSessionFactory' available: expected single matching bean but found 2: org.mybatis.spring.SqlSessionFactoryBean#0,org.mybatis.spring.SqlSessionFactoryBean#1
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1526)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1406)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1290)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1210)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640)
... 42 more
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.apache.ibatis.session.SqlSessionFactory' available: expected single matching bean but found 2: org.mybatis.spring.SqlSessionFactoryBean#0,org.mybatis.spring.SqlSessionFactoryBean#1
at org.springframework.beans.factory.config.DependencyDescriptor.resolveNotUnique(DependencyDescriptor.java:220)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1268)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1210)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1511)
... 53 more
Process finished with exit code -1
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceimpl': Unsatisfied dependency expressed through field 'userMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userMapper' defined in file [E:\javacode\springmvc006-ssm\target\classes\com\peihj\Mapper\UserMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.apache.ibatis.session.SqlSessionFactory' available: expected single matching bean but found 2: org.mybatis.spring.SqlSessionFactoryBean#0,org.mybatis.spring.SqlSessionFactoryBean#1
导致原因:org . spring framework . beans . factory . unsatisfieddependencyexception:创建名为“userServiceimpl”的bean时出错:通过字段“userMapper”表示的未满足的依赖关系;嵌套异常为org . spring framework . beans . factory . unsatisfieddependencyexception:创建在文件[E:\ javacode \ spring MVC 006-SSM \ target \ classes \ com \ Pei HJ \ Mapper \ userMapper . class]中定义的名为“user Mapper”的bean时出错:通过bean属性“sqlSessionFactory”表示的不满足的依赖关系;嵌套异常为org . spring framework . beans . factory . nouniquebeandidefinitionexception:没有“org . Apache . ibatis . session . sqlsessionfactory”类型的合格bean可用:应为单个匹配bean,但找到了2:org . mybatis . spring . sqlsessionfactorybean # 0,org . mybatis . spring . sqlsessionfactorybean # 1
翻译过来如下是因为创建了两个javabean,属于配置文件application_service出错
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<!--添加包扫描-->
<import resource="applicationContext_mapper.xml"/>
<context:component-scan base-package="com.peihj.Service"/>
<!--添加事务管理器-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!--配置数据源,只要保证名称一样就可以引用过来-->
<property name="dataSource" ref="datasource"></property>
</bean>
<!--配置事务切面-->
<!--
PROPAGATION_REQUIRED支持当前事务,如果当前没有事务,就新建一个事务。这是最常见的选择。
· PROPAGATION_SUPPORTS支持当前事务,如果当前没有事务,就以非事务方式执行。
· PROPAGATION_MANDATORY支持当前事务,如果当前没有事务,就抛出异常。
· PROPAGATION_REQUIRES_NEW新建事务,如果当前存在事务,把当前事务挂起。
· PROPAGATION_NOT_SUPPORTED以非事务方式执行操作,如果当前存在事务,就把当前事务挂起。
· PROPAGATION_NEVER以非事务方式执行,如果当前存在事务,则抛出异常。
-->
<tx:advice id="myadvice" transaction-manager="transactionManager">
<tx:attributes>
<!--
tx:method:给具体的方法配置事务属性、可以有多个、分别给不同的方法配置属性
name:方法名称、不要带包名。也可以使用通配符 * 表示任意字符
propagation:传播行为
isolation:隔离级别
rollback-for:指定的异常类名、全限定类名。发生异常先和这里边的进行比对
如果发生的异常类型是这里边的,就回滚,如果不是、而是运行时异常、也会回滚-->
<!-- 其中*为通配符,即代表以save为开头的所有方法,即表示符合此命名规则的方法作为一个事务。-->
<!-- propagation="REQUIRED"代表支持当前事务,如果当前没有事务,就新建一个事务。这是最常见的选择。-->
<tx:method name="*select*" read-only="true"/>
<tx:method name="*find*" read-only="true"/>
<tx:method name="*search*" read-only="true"/>
<tx:method name="*get*" read-only="true"/>
<tx:method name="*insert*" propagation="REQUIRED"/>
<tx:method name="*add*" propagation="REQUIRED"/>
<tx:method name="*save*" propagation="REQUIRED"/>
<tx:method name="*set*" propagation="REQUIRED"/>
<tx:method name="*update*" propagation="REQUIRED"/>
<tx:method name="*change*" propagation="REQUIRED"/>
<tx:method name="*delete*" propagation="REQUIRED"/>
<tx:method name="*drop*" propagation="REQUIRED"/>
<tx:method name="*remove*" propagation="REQUIRED"/>
<tx:method name="*clean*" propagation="REQUIRED"/>
<tx:method name="*" propagation="SUPPORTS"/>
</tx:attributes>
</tx:advice>
<!--配置切入点+绑定-->
<!-- 配置参与事务的类 -->
<aop:config>
<!-- 其中第一个*代表返回值,第二*代表service下子包,第三个*代表方法名,“(..)”代表方法参数。-->
<aop:pointcut id="mycut" expression="execution(* com.peihj.Service.*.*(..))"/>
<aop:advisor advice-ref="myadvice" pointcut-ref="mycut"/>
</aop:config>
</beans>
是因为我在application_mapper中创建时已经通过sqlsessionfactorybean ,一个合格的sqlsessionfactory”类型的合格bean可用:应为单个匹配bean,但找到了2个:org . mybatis . spring . sqlsessionfactorybean # 0,org . mybatis . spring . sqlsessionfactorybean,因为我在配置service时候,配置数据源的时候datasource爆红,所以我进行了引用
,以至于程序创建了两个sqlsessionfactorybean。所以将
注释了就好了。