应用Spring,启动tomcat时Error listenerStart 和 Could not open ServletContext resource

一。运用Spring时,一启动tomcat就出错Error listenerStart,查看tomcat日志,发现错误信息如下:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool

显然是数据源加载失败,修改数据源配置,一般即可(可参考博文http://xuthus.iteye.com/blog/85089)。Spring的数据源有JDBC方式和应用tomcat连接池方式,顺便写一下:
1.JDBC方式

	    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">   
	        <property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver" />   
	        <property name="url" value="jdbc:db2://192.168.3.186:50000/TEST" />   
	        <property name="username" value="db2admin" />   
	        <property name="password" value="db2admin" />   
	    </bean> 



2.使用连接池
    	<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean" destroy-method="close">
	        <property name="jndiName" value="java:comp/env/jdbc/test">
	      	</property>
		</bean>





二。关于Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
是由于web.xml中配置没配对,或没配,如下

    <context-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>
              /WEB-INF/classes/applicationContext.xml
       </param-value>
    </context-param>

你可能感兴趣的:(java,spring,tomcat,bean,Web)