java 找不到类 org.apache.commons.dbcp.BasicDataSource
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25792321/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Class org.apache.commons.dbcp.BasicDataSource not found
提问by Programmer254
<?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>
Below is the error I am getting.
下面是我得到的错误。
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)
I am also getting "The fully qualified name of the bean's class, except if it serves only as a parent definition for child bean definitions." when I hover my mouse over class="org.apache.commons.dbcp.BasicDataSource" What does it mean?
我还收到“bean 类的完全限定名称,除非它仅用作子 bean 定义的父定义。” 当我将鼠标悬停在 class="org.apache.commons.dbcp.BasicDataSource" 上时,这是什么意思?
Could someone help me resolve the issue. I am trying to work on a simple spring hibernate and mysql. Thanks.
有人可以帮我解决这个问题。我正在尝试使用简单的 spring 休眠和 mysql。谢谢。
回答by Padi
Also adding this dependency to pom.xml worked for me :)
还将此依赖项添加到 pom.xml 对我有用:)
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
回答by Xavier Delamotte
I think your error is more related to the fact that you are using an XML namespace without declaring it.
我认为您的错误与您使用 XML 命名空间而不声明它的事实更相关。
As explainted in this answer. Try to add http://www.springframework.org/schema/context/spring-context.xsd
to the schemaLocation:
如本答案所述。尝试添加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">