未找到类org.apache.commons.dbcp.BasicDataSource

时间:2014-09-11 16:12:01

标签: java spring hibernate spring-mvc

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans    http://www.springframework.org/schema/beans/spring-beans.xsd"
    xmlns:context="http://www.springframework.org/schema/context">

   <context:annotation-config/>


<context:component-scan base-package="org.dao.impl"/>

<bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">  
    <property name="driverClassName" value="${db.driver}"/>
    <property name="url" value="${db.jdbcurl}; create=true"/>
    <property name="username" value="${db.username}"/>
    <property name="password" value="${db.password}"/>
    <property name="initialSize" value="3"/>
</bean>

以下是我得到的错误。

Sep 11, 2014 12:03:45 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1d33a6b: startup date [Thu Sep 11 12:03:45 EDT 2014]; root of context hierarchy
Sep 11, 2014 12:03:45 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [spring.xml]
Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 7 in XML document from class path resource [spring.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 7; columnNumber: 30; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:annotation-config'.
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:335)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)

我也得到了“bean类的完全限定名,除非它仅用作子bean定义的父定义。”当我将鼠标悬停在class =“org.apache.commons.dbcp.BasicDataSource”上时是什么意思?

有人可以帮我解决这个问题。我正在尝试一个简单的春天hibernate和mysql。感谢。

3 个答案:

答案 0 :(得分:3)

同样将此依赖项添加到pom.xml对我有用:)

gcloud config set

答案 1 :(得分:2)

我认为您的错误与您使用XML命名空间而不声明错误更为相关。

如[{3}}中所述。尝试将http://www.springframework.org/schema/context/spring-context.xsd添加到schemaLocation:

<?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:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context.xsd">

答案 2 :(得分:-1)

添加 buildPath commons-dpcp2.jar , 如果您无法使用它,请按照this link

下载并添加Eclipse的构建路径。