背景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
我要试试这个。我一定错过了那部分文档。 –