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删除。



猜您在找 错误之Request processing failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'transactionManager' is defined 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 使用springmvc时报错org.springframework.beans.NullValueInNestedPathException: Invalid property 'department' of bean class [com.atguigu.springmvc.crud.entities.Employee]: org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'null' to required type 'double' for property 'band'; nested exception is org.springframework.core.convert.Con mybatis Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'homeControll Initialization of bean failed; nested exception is java.lang. org.springframework.beans.MethodInvocationException: Property 'cacheManager' threw exception; nested exception is org.apache.shiro.cache.CacheException: net.sf.ehcache.CacheException: Caches cannot be org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested ?--Porg.springframework.beans.MethodInvocationException: Property 'username' threw exception; nested exception is java.lang.NullPointerException 【flyway】Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' def
 
粤ICP备18138465号  © 2018-2026 CODEPRJ.COM