![](/img/trans.png)
[英]java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource
[英]Class org.apache.commons.dbcp.BasicDataSource not found
<?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”上是什么意思?
有人可以帮我解决问题。 我正在尝试在简单的Spring Hibernate和mysql上工作。 谢谢。
也将此依赖项添加到pom.xml对我有用:)
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
我认为您的错误与您使用XML命名空间而不声明它的事实有关。
正如在这个答案中所解释的 。 尝试将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">
添加buildPath commons-dpcp2.jar
,如果您不可用,请单击此链接 。
下载并添加Eclipse的构建路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.