spring依赖注入失败,找不到applicationContext,实在找不到原因了,网上说的我都看了,还是没用

麦秆菊 发布于 2016/12/28 11:27
阅读 912
收藏 0

具体错误:

java.lang.IllegalStateException: Failed to load ApplicationContext

 at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
 at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:122)
 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:321)
 at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
 at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
 at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
 at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:284)
 at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
 at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
 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:71)
 at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
 at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
 at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
 at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
 at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
 at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:253)
 at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testAction': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.dalen.readorwrite.services.IOrganService com.dalen.readorwrite.actions.testAction.organService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'organService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.dalen.readorwrite.db.dao.OrganMapper com.dalen.readorwrite.services.impl.OrganService.organMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.dalen.readorwrite.db.dao.OrganMapper] 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)}
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userInfoMapper': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public final void org.mybatis.spring.support.SqlSessionDaoSupport.setSqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in URL [file:config/applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [G:\up366_java\readorwrite\WebRoot\WEB-INF\classes\com\dalen\readorwrite\db\mapper\OrganMapper.xml]'; nested exception is java.lang.RuntimeException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class . Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'com.up366.school.db.pojo.Organ'.  Cause: java.lang.ClassNotFoundException: Cannot find class: com.up366.school.db.pojo.Organ
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'organMapper': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public final void org.mybatis.spring.support.SqlSessionDaoSupport.setSqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in URL [file:config/applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [G:\up366_java\readorwrite\WebRoot\WEB-INF\classes\com\dalen\readorwrite\db\mapper\OrganMapper.xml]'; nested exception is java.lang.RuntimeException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class . Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'com.up366.school.db.pojo.Organ'.  Cause: java.lang.ClassNotFoundException: Cannot find class: com.up366.school.db.pojo.Organ
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'organMapper': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public final void org.mybatis.spring.support.SqlSessionDaoSupport.setSqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in URL [file:config/applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [G:\up366_java\readorwrite\WebRoot\WEB-INF\classes\com\dalen\readorwrite\db\mapper\OrganMapper.xml]'; nested exception is java.lang.RuntimeException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class . Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'com.up366.school.db.pojo.Organ'.  Cause: java.lang.ClassNotFoundException: Cannot find class: com.up366.school.db.pojo.Organ
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userInfoMapper': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public final void org.mybatis.spring.support.SqlSessionDaoSupport.setSqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in URL [file:config/applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [G:\up366_java\readorwrite\WebRoot\WEB-INF\classes\com\dalen\readorwrite\db\mapper\OrganMapper.xml]'; nested exception is java.lang.RuntimeException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class . Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'com.up366.school.db.pojo.Organ'.  Cause: java.lang.ClassNotFoundException: Cannot find class: com.up366.school.db.pojo.Organ
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userInfoMapper': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public final void org.mybatis.spring.support.SqlSessionDaoSupport.setSqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in URL [file:config/applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [G:\up366_java\readorwrite\WebRoot\WEB-INF\classes\com\dalen\readorwrite\db\mapper\OrganMapper.xml]'; nested exception is java.lang.RuntimeException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class . Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'com.up366.school.db.pojo.Organ'.  Cause: java.lang.ClassNotFoundException: Cannot find class: com.up366.school.db.pojo.Organ
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'organMapper': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public final void org.mybatis.spring.support.SqlSessionDaoSupport.setSqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in URL [file:config/applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [G:\up366_java\readorwrite\WebRoot\WEB-INF\classes\com\dalen\readorwrite\db\mapper\OrganMapper.xml]'; nested exception is java.lang.RuntimeException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class . Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'com.up366.school.db.pojo.Organ'.  Cause: java.lang.ClassNotFoundException: Cannot find class: com.up366.school.db.pojo.Organ
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'organMapper': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public final void org.mybatis.spring.support.SqlSessionDaoSupport.setSqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in URL [file:config/applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [G:\up366_java\readorwrite\WebRoot\WEB-INF\classes\com\dalen\readorwrite\db\mapper\OrganMapper.xml]'; nested exception is java.lang.RuntimeException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class . Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'com.up366.school.db.pojo.Organ'.  Cause: java.lang.ClassNotFoundException: Cannot find class: com.up366.school.db.pojo.Organ
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userInfoMapper': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public final void org.mybatis.spring.support.SqlSessionDaoSupport.setSqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in URL [file:config/applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [G:\up366_java\readorwrite\WebRoot\WEB-INF\classes\com\dalen\readorwrite\db\mapper\OrganMapper.xml]'; nested exception is java.lang.RuntimeException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class . Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'com.up366.school.db.pojo.Organ'.  Cause: java.lang.ClassNotFoundException: Cannot find class: com.up366.school.db.pojo.Organ
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1146)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:633)
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
 at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:120)
 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:248)
 at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)
 at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)
 ... 24 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.dalen.readorwrite.services.IOrganService com.dalen.readorwrite.actions.testAction.organService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'organService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.dalen.readorwrite.db.dao.OrganMapper com.dalen.readorwrite.services.impl.OrganService.organMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.dalen.readorwrite.db.dao.OrganMapper] 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)}
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:517)
 at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
 ... 40 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'organService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.dalen.readorwrite.db.dao.OrganMapper com.dalen.readorwrite.services.impl.OrganService.organMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.dalen.readorwrite.db.dao.OrganMapper] 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)}
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1146)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:917)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:860)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:775)
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:489)
 ... 42 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.dalen.readorwrite.db.dao.OrganMapper com.dalen.readorwrite.services.impl.OrganService.organMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.dalen.readorwrite.db.dao.OrganMapper] 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)}
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:517)
 at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
 ... 53 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.dalen.readorwrite.db.dao.OrganMapper] 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)}
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:993)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:863)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:775)
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:489)
 ... 55 more


我的applicationContext.xml配置:

<context:annotation-config />  <context:component-scan base-package="com.dalen.readorwrite" />   <!-- 数据库连接start -->  <!-- 读取配置文件 -->  <context:property-placeholder location="classpath:jdbc_master.properties,classpath:jdbc_slave.properties" />   <bean id="masterDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">  <property name="driverClass" value="${master.driverClass}" />  <property name="jdbcUrl" value="${master.jdbcUrl}&amp;autoReconnect=true&amp;failOverReadOnly=false" />  <property name="user" value="${master.user}" />  <property name="password" value="${master.password}" />  <property name="minPoolSize" value="${master.minPoolSize}" />  <!--连接池中保留的最大连接数。默认为15-->  <property name="maxPoolSize" value="${master.maxPoolSize}"/>  <!--最大空闲时间,超过空闲时间的连接将被丢弃。为0或负数则永不丢弃。默认为0-->  <property name="maxIdleTime" value="${master.maxIdleTime}" />  <!--当连接池中的连接用完时,C3P0一次性创建新连接的数目-->  <property name="acquireIncrement" value="${master.acquireIncrement}" />  <!--JDBC的标准参数,用以控制数据源内加载的PreparedStatement数量。但由于预缓存的Statement属于单个Connection而不是整个连接池,所以设置这个参数需要考虑到多方面的因素,如果maxStatements与 maxStatementsPerConnection均为0,则缓存被关闭。默认为0-->  <property name="maxStatements" value="${master.maxStatements}" />  <!--初始化时创建的连接数,应在minPoolSize与maxPoolSize之间取值。默认为3-->  <property name="initialPoolSize" value="${master.initialPoolSize}" />  <!--隔多少秒检查所有连接池中的空闲连接,默认为0表示不检查-->  <property name="idleConnectionTestPeriod" value="${master.idleConnectionTestPeriod}" />  <!--定义在从数据库获取新连接失败后重复尝试获取的次数,默认为30-->  <property name="acquireRetryAttempts" value="${master.acquireRetryAttempts}" />  <!--获取连接失败将会引起所有等待获取连接的线程抛出异常。但是数据源仍有效保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试获取连接失败后该数据源将申明已断开并永久关闭。默认为 false-->  <property name="breakAfterAcquireFailure" value="${master.breakAfterAcquireFailure}" />  <!--如果设为true那么在取得连接的同时将校验连接的有效性。默认为false-->  <property name="testConnectionOnCheckin" value="${master.testConnectionOnCheckin}" />  <!--因性能消耗大请只在需要的时候使用它。如果设为true那么在每个connection提交的时候都将校验其有效性。 建议使用idleConnectionTestPeriod或automaticTestTable 等方法来提升连接测试的性能。默认为false-->  <property name="testConnectionOnCheckout" value="${master.testConnectionOnCheckout}" />  <!--连接关闭时默认将所有未提交的操作回滚。默认为false-->  <property name="autoCommitOnClose" value="${master.autoCommitOnClose}" />  <!--C3P0是异步操作的,缓慢的JDBC操作通过帮助进程完成。扩展这些操作可以有效的提升性能,通过多线程实现多个操作同时被执行。默认为3-->  <property name="numHelperThreads" value="${master.numHelperThreads}" />  <!--  acquireRetryDelay:两次连接中间隔时间,单位毫秒,默认为1000  automaticTestTable:C3P0将建一张名为Test的空表,并使用其自带的查询语句进行测试。如果定义了这个参数,那么属性preferredTestQuery将被忽略。你不能在这张Test表上进行任何操作,它将中为C3P0测试所用,默认为null  checkoutTimeout:当连接池用完时客户端调用getConnection()后等待获取新连接的时间,超时后将抛出SQLException,如设为0则无限期等待。单位毫秒,默认为0  connectionTesterClassName: 通过实现ConnectionTester或QueryConnectionTester的类来测试连接,类名需设置为全限定名。默认为 com.mchange.v2.C3P0.impl.DefaultConnectionTester  maxStatementsPerConnection:连接池内单个连接所拥有的最大缓存Statement数。默认为0  preferredTestQuery:定义所有连接测试都执行的测试语句。在使用连接测试的情况下这个参数能显著提高测试速度。测试的表必须在初始数据源的时候就存在。默认为null;  propertyCycle: 用户修改系统配置参数执行前最多等待的秒数。默认为300;  -->  </bean>   <bean id="slaveDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">  <property name="driverClass" value="${slave.driverClass}" />  <property name="jdbcUrl" value="${slave.jdbcUrl}" />  <property name="user" value="${slave.user}" />  <property name="password" value="${slave.password}" />  <property name="minPoolSize" value="${slave.minPoolSize}"/>  <property name="maxPoolSize" value="${slave.maxPoolSize}"/>  <property name="maxIdleTime" value="${slave.maxIdleTime}"/>  <property name="acquireIncrement" value="${slave.acquireIncrement}"/>  <property name="maxStatements" value="${slave.maxStatements}"/>  <property name="initialPoolSize" value="${slave.initialPoolSize}"/>  <property name="idleConnectionTestPeriod" value="${slave.idleConnectionTestPeriod}"/>  <property name="acquireRetryAttempts" value="${slave.acquireRetryAttempts}"/>  <property name="breakAfterAcquireFailure" value="${slave.breakAfterAcquireFailure}"/>  <property name="testConnectionOnCheckout" value="${slave.testConnectionOnCheckout}"/>  <property name="autoCommitOnClose" value="${slave.autoCommitOnClose}"/>  </bean>   <!--定义数据源,使用自己定义的数据源-->  <bean id="myDynamicDataSource" class="com.dalen.readorwrite.db.datasource.DynamicSource">  <property name="targetDataSources">  <!--标识符类型-->  <map key-type="java.lang.String">  <entry key="master" value-ref="masterDataSource" />  <entry key="slave" value-ref="slaveDataSource" />  </map>  </property>  <property name="defaultTargetDataSource" ref="masterDataSource" />  </bean>   <!--配置数据库aop注解-->  <aop:aspectj-autoproxy />  <bean id="myDataSourceAspect" class="com.dalen.readorwrite.db.datasource.DataSourceAspect">  <property name="sqlSessionFactory" ref="sqlSessionFactory" />  </bean>  <aop:config>  <aop:aspect id="myAspect" ref="myDataSourceAspect">  <aop:pointcut id="tx" expression="execution(* com.dalen.readorwrite.db.dao.*.*(..))" />  <aop:before method="before" pointcut-ref="tx" />  </aop:aspect>  </aop:config>   <tx:annotation-driven />  <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  <property name="dataSource" ref="myDynamicDataSource" />  <property name="typeAliasesPackage" value="com.dalen.readorwrite.db.pojo" />  <property name="mapperLocations" value="classpath:com/dalen/readorwrite/db/mapper/*Mapper.xml" />  </bean>   <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  <property name="basePackage" value="com.dalen.readorwrite.db.dao" />  </bean>

加载中
0
麦秆菊
麦秆菊

这是我的配置信息

<context:annotation-config />
    <context:component-scan base-package="com.dalen.readorwrite" />

    <!-- 数据库连接start -->
    <!-- 读取配置文件 -->
    <context:property-placeholder location="classpath:jdbc_master.properties,classpath:jdbc_slave.properties" />
    <bean id="masterDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
        <property name="driverClass" value="${master.driverClass}" />
        <property name="jdbcUrl" value="${master.jdbcUrl}&amp;autoReconnect=true&amp;failOverReadOnly=false" />
        <property name="user" value="${master.user}" />
        <property name="password" value="${master.password}" />
        <property name="minPoolSize" value="${master.minPoolSize}" />
        <!--连接池中保留的最大连接数。默认为15-->
        <property name="maxPoolSize" value="${master.maxPoolSize}"/>
        <!--最大空闲时间,超过空闲时间的连接将被丢弃。为0或负数则永不丢弃。默认为0-->
        <property name="maxIdleTime" value="${master.maxIdleTime}" />
        <!--当连接池中的连接用完时,C3P0一次性创建新连接的数目-->
        <property name="acquireIncrement" value="${master.acquireIncrement}" />
        <!--JDBC的标准参数,用以控制数据源内加载的PreparedStatement数量。但由于预缓存的Statement属于单个Connection而不是整个连接池,所以设置这个参数需要考虑到多方面的因素,如果maxStatements与 maxStatementsPerConnection均为0,则缓存被关闭。默认为0-->
        <property name="maxStatements" value="${master.maxStatements}" />
        <!--初始化时创建的连接数,应在minPoolSize与maxPoolSize之间取值。默认为3-->
        <property name="initialPoolSize" value="${master.initialPoolSize}" />
        <!--隔多少秒检查所有连接池中的空闲连接,默认为0表示不检查-->
        <property name="idleConnectionTestPeriod" value="${master.idleConnectionTestPeriod}" />
        <!--定义在从数据库获取新连接失败后重复尝试获取的次数,默认为30-->
        <property name="acquireRetryAttempts" value="${master.acquireRetryAttempts}" />
        <!--获取连接失败将会引起所有等待获取连接的线程抛出异常。但是数据源仍有效保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试获取连接失败后该数据源将申明已断开并永久关闭。默认为 false-->
        <property name="breakAfterAcquireFailure" value="${master.breakAfterAcquireFailure}" />
        <!--如果设为true那么在取得连接的同时将校验连接的有效性。默认为false-->
        <property name="testConnectionOnCheckin" value="${master.testConnectionOnCheckin}" />
        <!--因性能消耗大请只在需要的时候使用它。如果设为true那么在每个connection提交的时候都将校验其有效性。
建议使用idleConnectionTestPeriod或automaticTestTable 等方法来提升连接测试的性能。默认为false-->
        <property name="testConnectionOnCheckout" value="${master.testConnectionOnCheckout}" />
        <!--连接关闭时默认将所有未提交的操作回滚。默认为false-->
        <property name="autoCommitOnClose" value="${master.autoCommitOnClose}" />
        <!--C3P0是异步操作的,缓慢的JDBC操作通过帮助进程完成。扩展这些操作可以有效的提升性能,通过多线程实现多个操作同时被执行。默认为3-->
        <property name="numHelperThreads" value="${master.numHelperThreads}" />
        <!--
            acquireRetryDelay:两次连接中间隔时间,单位毫秒,默认为1000
            automaticTestTable:C3P0将建一张名为Test的空表,并使用其自带的查询语句进行测试。如果定义了这个参数,那么属性preferredTestQuery将被忽略。你不能在这张Test表上进行任何操作,它将中为C3P0测试所用,默认为null
            checkoutTimeout:当连接池用完时客户端调用getConnection()后等待获取新连接的时间,超时后将抛出SQLException,如设为0则无限期等待。单位毫秒,默认为0
            connectionTesterClassName: 通过实现ConnectionTester或QueryConnectionTester的类来测试连接,类名需设置为全限定名。默认为 com.mchange.v2.C3P0.impl.DefaultConnectionTester
            maxStatementsPerConnection:连接池内单个连接所拥有的最大缓存Statement数。默认为0
            preferredTestQuery:定义所有连接测试都执行的测试语句。在使用连接测试的情况下这个参数能显著提高测试速度。测试的表必须在初始数据源的时候就存在。默认为null;
            propertyCycle: 用户修改系统配置参数执行前最多等待的秒数。默认为300;
        -->
    </bean>
    <bean id="slaveDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
        <property name="driverClass" value="${slave.driverClass}" />
        <property name="jdbcUrl" value="${slave.jdbcUrl}" />
        <property name="user" value="${slave.user}" />
        <property name="password" value="${slave.password}" />
        <property name="minPoolSize" value="${slave.minPoolSize}"/>
        <property name="maxPoolSize" value="${slave.maxPoolSize}"/>
        <property name="maxIdleTime" value="${slave.maxIdleTime}"/>
        <property name="acquireIncrement" value="${slave.acquireIncrement}"/>
        <property name="maxStatements" value="${slave.maxStatements}"/>
        <property name="initialPoolSize" value="${slave.initialPoolSize}"/>
        <property name="idleConnectionTestPeriod" value="${slave.idleConnectionTestPeriod}"/>
        <property name="acquireRetryAttempts" value="${slave.acquireRetryAttempts}"/>
        <property name="breakAfterAcquireFailure" value="${slave.breakAfterAcquireFailure}"/>
        <property name="testConnectionOnCheckout" value="${slave.testConnectionOnCheckout}"/>
        <property name="autoCommitOnClose" value="${slave.autoCommitOnClose}"/>
    </bean>
    <!--定义数据源,使用自己定义的数据源-->
    <bean id="myDynamicDataSource" class="com.dalen.readorwrite.db.datasource.DynamicSource">
        <property name="targetDataSources">
            <!--标识符类型-->
            <map key-type="java.lang.String">
                <entry key="master" value-ref="masterDataSource" />
                <entry key="slave" value-ref="slaveDataSource" />
            </map>
        </property>
        <property name="defaultTargetDataSource" ref="masterDataSource" />
    </bean>
    <!--配置数据库aop注解-->
    <aop:aspectj-autoproxy />
    <bean id="myDataSourceAspect" class="com.dalen.readorwrite.db.datasource.DataSourceAspect">
        <property name="sqlSessionFactory" ref="sqlSessionFactory" />
    </bean>
    <aop:config>
        <aop:aspect id="myAspect" ref="myDataSourceAspect">
            <aop:pointcut id="tx" expression="execution(* com.dalen.readorwrite.db.dao.*.*(..))" />
            <aop:before method="before" pointcut-ref="tx" />
        </aop:aspect>
    </aop:config>
    <tx:annotation-driven />
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="myDynamicDataSource" />
        <property name="typeAliasesPackage" value="com.dalen.readorwrite.db.pojo" />
        <property name="mapperLocations" value="classpath:com/dalen/readorwrite/db/mapper/*Mapper.xml" />
    </bean>
   
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.dalen.readorwrite.db.dao" />
    </bean>
0
tinshen
tinshen
Could not resolve type alias 'com.up366.school.db.pojo.Organ'.  Cause: java.lang.ClassNotFoundException: Cannot find class: com.up366.school.db.pojo.Organ
麦秆菊
麦秆菊
恩,特别感谢,找到原因了,就是这个找不到导致的
0
sxgkwei
sxgkwei
OrganMapper.xml   报错
麦秆菊
麦秆菊
恩,谢谢,找到原因了
返回顶部
顶部