Initialization of bean failed; nested exception is org.springframework.beans.InvalidPropertyException: Invalid property 'dataSource' of bean class [com.liuyang.jdbc.PersonDao]: No property 'dataSource


這個錯誤是說我的啟動失敗了。這類問題要從配置文件中開始找原因,我用的是spring框架,所以我從application.中找的原因

然后對比路徑,對比文件的命名和id,都沒有問題,為什么會在啟動的時候找不到dataSource,我想到應該是少包,但是,找尋發現包也沒有問題。

最后發現是這里錯了

這里是重點:::!!!!!

     我的getter和setter的方法中設置的dateSource,而配置文件想要注入的是dataSource,兩個名稱不一致,難怪機器找不到我的文件的class,更改

           

<bean id="dataSource" destroy-method="close"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>

<bean id="personDao" class="com.liuyang.jdbc.PersonDao">
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>

這里所有的dataSource為dateSource,或者更改類中的名稱,dateSource為dataSource,連同getter和setter一起才有效。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'URIType' of bean class Property 'dataSource' threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'dataSource' threw exception spring和mybatis整合報錯:org.springframework.beans.MethodInvocationException: Property 'dataSource' threw exception; nested exception is java.lang.NoClassDefFoundError 【錯誤解決】Error creating bean with name 'transactionManager' :nested exception is java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/ 使用springmvc時報錯org.springframework.beans.NullValueInNestedPathException: Invalid property 'department' of bean class [com.atguigu.springmvc.crud.entities.Employee]: Cannot resolve reference to bean 'mongoTemplate' while setting bean property 'mongoOperations'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with na org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.jdbc.datasource.DataSourceTransactionManager#0' defined in class path resource [spring-mybat org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [bean.xml]: Invocation of init method failed; nested exception is 錯誤之Request processing failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'transactionManager' is defined
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM