为了账号安全,请及时绑定邮箱和手机立即绑定

Failed to load ApplicationContext怎么破

Failed to load ApplicationContext这个怎么破啊。。。是在想不出来,@ContextConfiguration("classpath:spring-transaction.xml")也加了这句话,JDK也是1.6版本的。就是在.xml文件里面的内容不一样

<?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: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/aop 

        http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">

    

<!--配置c3p0连接池 -->

<bean id="datasource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">

<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>

<property name="url" value="jdbc:mysql://localhost:3306/spring-transaction?useUnicode=true&amp;characterEncoding=utf-8"></property>

<property name="username" value="root"/>

<property name="password" value="123456" />    

</bean>     

    <!--配置业务层类  -->   

    <bean id="accountService" class="cn.pyh.spring.demo1.AccountServiceImpl">

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

    </bean>

    <!-- 配置DAO的类 -->

    <bean id="accountDao" class="cn.pyh.spring.demo1.AccountDaoImpl">

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

    </bean>

        

 </beans>


正在回答

3 回答

其实,就是老师的讲课速度很快。我们在所难免的打错了一些配置。改过来就好了

0 回复 有任何疑惑可以回复我~

他喵的,原来是XML文件中的dataSource要S要大写。。。

2 回复 有任何疑惑可以回复我~
#1

慕莱坞yql

你好,请问是哪个文件里的?
2018-08-23 回复 有任何疑惑可以回复我~

报错信息如下:

2017-2-6 13:47:07 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions

信息: Loading XML bean definitions from class path resource [spring-transaction.xml]

2017-2-6 13:47:07 org.springframework.context.support.GenericApplicationContext prepareRefresh

信息: Refreshing org.springframework.context.support.GenericApplicationContext@2c41d05d: startup date [Mon Feb 06 13:47:07 GMT+08:00 2017]; root of context hierarchy

2017-2-6 13:47:07 org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor <init>

信息: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring

2017-2-6 13:47:07 org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName

信息: Loaded JDBC driver: com.mysql.jdbc.Driver

2017-2-6 13:47:07 org.springframework.test.context.TestContextManager prepareTestInstance

严重: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@68302e67] to prepare test instance [cn.pyh.spring.demo1.SpringDemo@3336a1a1]

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:331)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:213)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:290)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:292)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:233)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)

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:300)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:176)

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.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountService' defined in class path resource [spring-transaction.xml]: Cannot resolve reference to bean 'accountDao' while setting bean property 'accountDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountDao' defined in class path resource [spring-transaction.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'datasource' of bean class [cn.pyh.spring.demo1.AccountDaoImpl]: Bean property 'datasource' is not writable or has an invalid setter method. Did you mean 'dataSource'?

at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:336)

at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)

at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:125)

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.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountDao' defined in class path resource [spring-transaction.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'datasource' of bean class [cn.pyh.spring.demo1.AccountDaoImpl]: Bean property 'datasource' is not writable or has an invalid setter method. Did you mean 'dataSource'?

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1493)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)

at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)

... 43 more

Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'datasource' of bean class [cn.pyh.spring.demo1.AccountDaoImpl]: Bean property 'datasource' is not writable or has an invalid setter method. Did you mean 'dataSource'?

at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1064)

at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:922)

at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:82)

at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:62)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1489)

... 51 more


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

Failed to load ApplicationContext怎么破

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信