test 方法运行时出现的错误 : java.lang.IllegalStateException: Failed to load ApplicationContext

it2023-09-20  71

错误信息

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) … more

主要的问题的信息 Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlSessionFactory’ defined in file [D:\IdeaProjects\3-10-project\target\classes\spring\spring-dao.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type ‘java.lang.String’ to required type ‘javax.sql.DataSource’ for property ‘dataSource’; nested exception is java.lang.IllegalStateException: Cannot convert value of type ‘java.lang.String’ to required type ‘javax.sql.DataSource’ for property ‘dataSource’: no matching editors or conversion strategy found … more **问题出现在: 配置文件中的 sqlSessionFactory **

问题代码

问题代码出现在Spring-dao.xml文件中: <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" value="dataSource"></property> <property name="configLocation" value="classpath:mybatis/mybatis.xml"></property> </bean>

在sqlSessionFactory与dataSource 建立联系的过程中出现的小错误,但是影响很大

错误原因

下面代码中的 value 应改成 ref 否则就会导致"无法加载应用程序上下文"的问题. <!--此处的value应该改成 ref--> <property name="dataSource" value="dataSource"></property>

正确代码

<property name="dataSource" ref="dataSource"></property>

分享一些Java学习过程中遇到的错误, 如果有不足的地方,请各位大神指导

最新回复(0)