在做ssm整合的时候,提示容器在加载前被关闭,问题很明显,但是不知道错误在哪里了,并没有写网上所说的那种
ApplicationContext ctx = new ClassPathXmlApplicationContext(); 代码,就只是做了配置,然后启动项目的时候报错的。
请各位大神指出错误,感激不尽,积分可以增加的啊!
问题截图
项目目录:
web.xml文件
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<!-- 加载spring容器所需要的监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 指定spring配置文件路径 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/ApplicationContext.xml</param-value>
</context-param>
<!--dispatcher是spring mvc的入口,是一个能将请求分发到控制器的servlet -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 加载spring mvc的配置文件 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:dispatcher-servlet.xml</param-value>
</init-param>
<!-- servlet会随着容器一起加载 -->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
<!--拦截/*,这是一个错误的方式,请求可以走到Action中,但转到jsp时再次被拦截,不能访问到jsp。 拦截/,restful风格 弊端:会导致静态文件(jpg,js,css)被拦截后不能正常显示。解决办法看dispatcher -->
</servlet-mapping>
<!-- 字符集 过滤器 -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list>
<!-- 配置session超时时间,单位分钟 -->
<session-config>
<session-timeout>15</session-timeout>
</session-config>
</web-app>
applocationContext.xml
<?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"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 测试spring环境,可删除 -->
<bean id="hello" class="com.spring.hello">
<property name="name">
<value>张敏</value>
</property>
</bean>
<!-- 扫描包 -->
<context:component-scan base-package="com.zm"></context:component-scan>
<!-- 配置数据库配置文件位置 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:db.properties"/>
</bean>
<!-- 根据配置文件的内容,配置数据源 -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<!-- 连接配置 -->
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!-- 使用mybatis弄成的sqlSessionFactory,指定了加载mybatis映射文件的地址 -->
<!-- <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
起了一个别名,这个地址下的类可以在mapper里面直接使用了
<property name="typeAliasesPackage" value="com.zm.model"/>
mapper的加载路径
<property name="mapperLocations">
<array>
<value>classpath:com/zm/mapper/*-mapper.xml</value>
</array>
</property>
</bean> -->
<!-- 配置Jdbc模板 -->
<bean id="jdbcTemplateOracle" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 事务控制 -->
<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!--符合下列name的,将进入到事务管理范畴 -->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="create*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="find*" propagation="SUPPORTS" read-only="true" />
<tx:method name="select*" propagation="SUPPORTS" read-only="true" />
<tx:method name="get*" propagation="SUPPORTS" read-only="true" />
</tx:attributes>
</tx:advice>
<!--定义一个切面,那些类的哪些方法参与事务-->
<aop:config>
<!-- 第一个*表示任意返回值类型,第二个*表示类,第三个*表示任意方法 (..)表示任意参数 -->
<aop:pointcut id="methodPointcut" expression="execution(* com.zm.service.*.*(..))"/>
<aop:advisor pointcut-ref="methodPointcut" advice-ref="txAdvice"/>
</aop:config>
</beans>
dispatcher-servlet.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="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
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<!-- springmvc的视图解析器,将视图名解析为url,同时将请求传递给requestdispatcher以显示视图 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 例如 a 那么会找到 web-inf/page/a.jsp-->
<property name="prefix" value="/page/"/>
<property name="suffix" value=".jsp"/>
</bean>
<mvc:default-servlet-handler />
<!-- @controller的使用前配置 -->
<mvc:annotation-driven/>
<!-- 扫描包 -->
<context:component-scan base-package="com.zm" >
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />
</context:component-scan>
<!-- springmvc的拦截器,每次在执行方法之前,都会进行一次session用户登陆的拦截,过滤掉了静态资源的拦截 -->
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**" />
<mvc:exclude-mapping path="/images/**" />
<mvc:exclude-mapping path="/css/**" />
<mvc:exclude-mapping path="/js/**" />
<mvc:exclude-mapping path="/checkLogin" />
<bean class="com.zm.interceptor.LoginInterceptor"/>
</mvc:interceptor>
</mvc:interceptors>
</beans>