zoukankan      html  css  js  c++  java
  • springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'jdbc' available

    异常名称:BeanInitializationException & NoSuchBeanDefinitionException

    异常分析:bean没有正确配置 由:No bean named 'jdbc' available 推测数据库配置bean出错

    异常原因:配置德鲁伊连接池时属性写错

    异常详情:


    七月 15, 2021 10:24:44 上午 org.springframework.context.support.AbstractApplicationContext refresh 警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanInitializationException: Could not process key 'jdbc.url' in PropertyOverrideConfigurer; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'jdbc' available org.springframework.beans.factory.BeanInitializationException: Could not process key 'jdbc.url' in PropertyOverrideConfigurer; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'jdbc' available at org.springframework.beans.factory.config.PropertyOverrideConfigurer.processProperties(PropertyOverrideConfigurer.java:114) at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:86) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:286) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:166) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:705) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85) at com.csn.web.Springdamo.test(Springdamo.java:16) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) 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.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'jdbc' available at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:775) at org.springframework.beans.factory.config.PropertyOverrideConfigurer.applyPropertyValue(PropertyOverrideConfigurer.java:149) at org.springframework.beans.factory.config.PropertyOverrideConfigurer.processKey(PropertyOverrideConfigurer.java:137) at org.springframework.beans.factory.config.PropertyOverrideConfigurer.processProperties(PropertyOverrideConfigurer.java:109) ... 30 more Process finished with exit code -1

    解决方案:检查德鲁伊连接池配置

    将property中name="driver"改为name="driverClassName"
        <!--配置druid德鲁伊连接池-->
        <bean id="druid" class="com.alibaba.druid.pool.DruidDataSource">
            <property name="username" value="root"></property>
            <property name="password" value="root"></property>
            <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
            <property name="url" value="jdbc:mysql://localhost:3306/xxxx"></property>
        </bean>
    解决结果:成功!
    错误等级:中级
    *注意事项:
    c3p0与
    druid配置虽然很像,但还是有一点不同,切换连接池时注意属性配置
    spring的配置加载第三方的properties文件时属性写错也会导致此错误
    eg:
    <context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>
    错写成
    <context:property-override location="classpath:jdbc.properties"></context:property-override>


  • 相关阅读:
    C#语句2——循环语句(for循环与for循环嵌套)
    C#语言基础
    C#几种截取字符串的方法小结
    SQL提取数据库表名,字段名等信息
    Winform绑定图片的三种方式
    C#中遍历各类数据集合的方法总结
    c#winform图片绘制与图片验证码
    DataGridView根据条件给单元格绑定图片
    C#Winform 父窗体 子窗体 传值
    一条Sql语句分组排序并且限制显示的数据条数
  • 原文地址:https://www.cnblogs.com/axibug/p/15014569.html
Copyright © 2011-2022 走看看