背景DBCP數據源
我是新來的春天。我正在使用Spring MVC 3和Springsource的spring工具套件。我正在運行它們提供的示例Spring模板。我爲我的數據源使用Apache DBCP。
問題
我已經能夠注入使用註釋咖啡豆,但我無法得到的容器來獲得我在我的servlet-context.xml文件中定義的數據源。內容如下。如果我自動裝載我的數據源,然後在任何地方使用它,我得到一個空指針異常,表明依賴沒有被注入。這適用於我嘗試自動裝配的任何其他課程。我非常肯定它與我在XML文件中定義我的bean 的方式有關,但我已經看到了幾種不同的方法,因此我不確定適合我的版本的是什麼。
<?xml version="1.0" encoding="UTF-8"?>
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0。 XSD http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd「服務器返回的錯誤的>
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<beans:property name="driverClassName" value="org.mysql.jdbc"/>
<beans:property name="url" value="jdbc:mysql://localhost:3306/mydb"/>
<beans:property name="username" value="root"/>
<beans:property name="password" value="admin"/>
</beans:bean>
<context:component-scan base-package="com.mycompany.myapp2" />
部分是
java.lang.NoClassDefFoundError: org/apache/commons/pool/KeyedObjectPoolFactory
我要試試這個。我一定錯過了那部分文檔。 –