在使用SSH添加
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
tomcat在启动的时候发生如下错误:
2008-9-28 11:13:01 org.apache.catalina.core.StandardContext start
严重: Error listenerStart
2008-9-28 11:13:01 org.apache.catalina.core.StandardContext start
严重: Context [/xxfire] startup failed due to previous errors
错误分析:
错误触发在web.xml中定义
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>/WEB-INF/context/ApplicationContext-*.xml</param-value>
- </context-param>
- <SPAN style="COLOR: #000000"><listener>
- <listener-class><SPAN style="BACKGROUND-COLOR: #ff6600">org.springframework.web.context.ContextLoaderListener</SPAN></listener-class>
- </listener></SPAN>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/context/ApplicationContext-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
检查spring配置管理xml文件。发现错误产生在:
- <bean id="dataSource" class="<SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ff6600">org.apache.commons.dbcp.BasicDataSource</SPAN>">
- <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
- <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"></property>
- <property name="username" value="sys8"></property>
- <property name="password" value="sys8"></property>
- </bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"></property>
<property name="username" value="sys8"></property>
<property name="password" value="sys8"></property>
</bean>
上面所示的代码中,红色代码是产生错误的根源,在spring管理Hibernate的dataSource是用的是:
- <SPAN style="COLOR: #000000">org.springframework.jdbc.datasource.DriverManagerDataSource</SPAN>
org.springframework.jdbc.datasource.DriverManagerDataSource
解决:
- <bean id="dataSource" class="<SPAN style="BACKGROUND-COLOR: #ff6600">org.springframework.jdbc.datasource.DriverManagerDataSource</SPAN>">
- <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
- <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"></property>
- <property name="username" value="sys8"></property>
- <property name="password" value="sys8"></property>
- </bean>