springmvc项目不用配置application.xml文件,web.xml不用加载contextlistener

来源:互联网 发布:北京seo排名 编辑:程序博客网 时间:2024/06/07 05:56

springMVC.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: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/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd       http://www.springframework.org/schema/context       http://www.springframework.org/schema/context/spring-context-3.0.xsd"><context:annotation-config /><!-- 把标记了注解的类转换为bean ,这里并不是只扫描controller,要不然concroller注入报错 --><context:component-scan base-package="com.chenjun.mall" /><!-- 数据源配置搁置 从appllicationContextx.xml中拿来的 --><context:property-placeholder location="classpath*:jdbc.properties" /><!-- 数据源的配置 <pre name="code" class="html">从appllicationContextx.xml中拿来的--><bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"destroy-method="close"><property name="driverClassName" value="${driver}" /><property name="url" value="${url}" /><property name="username" value="${user}" /><property name="password" value="${password}" /><!-- data source configuration --><property name="initialSize" value="60" /><!-- initial connections --><property name="maxActive" value="100" /><!-- MAX connections --><property name="maxIdle" value="50" /><!-- MAX idle connections --><property name="minIdle" value="10" /><!-- MIN idle connections --><!-- 处理mysql 8小时自动断开连接的问题 --><property name="testWhileIdle" value="true" /><property name="testOnBorrow" value="false" /><property name="testOnReturn" value="false" /><property name="validationQuery" value="select 1" /><property name="timeBetweenEvictionRunsMillis" value="20000" /><property name="numTestsPerEvictionRun" value="100" /></bean><!-- 事务相关控制 --><bean id="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource" /></bean><!-- MyBatis sqlSessionFactory 配置 mybatis --><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="configLocation" value="classpath:mybatis-config.xml" /><property name="dataSource" ref="dataSource" /></bean><bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate"><constructor-arg index="0" ref="sqlSessionFactory" /></bean><!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 --><!-- <bean --><!-- class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> --><!-- 视图 beans --><bean id="jspViewResolver"class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix"><value>/WEB-INF/jsp/</value></property><property name="suffix"><value>.jsp</value></property><property name="order" value="1" /><!-- 默认视图解析器 --></bean><!-- FreeMarker视图解析 如返回userinfo。。在这里配置后缀名ftl和视图解析器。。 --><bean id="freeMarkerViewResolver"class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"><property name="viewClass"value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" /><property name="suffix" value=".ftl" /><property name="contentType" value="text/html;charset=GBK" /><property name="exposeRequestAttributes" value="true" /><property name="exposeSessionAttributes" value="true" /><property name="exposeSpringMacroHelpers" value="true" /><property name="order" value="2" /></bean><!-- Controller 跳转的JSP页面路径 和 文件的后缀 --><!-- 避免IE在ajax请求时,返回json出现下载 --><bean id="jacksonMessageConverter"class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"><property name="supportedMediaTypes"><list><value>text/html;charset=UTF-8</value></list></property></bean><!-- 文件上传 --><bean id="multipartResolver"class="org.springframework.web.multipart.commons.CommonsMultipartResolver"><!-- set the max upload size100MB --><property name="maxUploadSize"><value>104857600</value></property><property name="maxInMemorySize"><value>1024000</value></property></bean></beans>

web.xml

<?xml version="1.0" encoding="UTF-8"?><web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee      http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"><display-name>eshop</display-name><!-- 如果Applicationcontext.xml的配置由springmvc.xml中来配置 , 注释是springmvc项目可不要的,因为不用listener来加载配置文件了,所以可不用--><!-- <context-param> --><!-- <param-name>contextConfigLocation</param-name> --><!-- <param-value>classpath*:ApplicationContext.xml</param-value> --><!-- </context-param> --><!-- <listener> --><!-- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class><!-- 以spring方式启动 --> <!-- </listener> --><!-- springMVC核心配置 --><servlet><servlet-name>springmvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!-- 该工程为springmvc项目 --><init-param><param-name>contextConfigLocation</param-name><param-value>classpath*:SpringMVC.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>springmvc</servlet-name><url-pattern>/</url-pattern></servlet-mapping><!-- <filter> --><!-- <filter-name>encodingFilter</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>encodingFilter</filter-name> --><!-- <url-pattern>/*</url-pattern> --><!-- </filter-mapping> --><!-- 读取spring配置文件 --><!-- <context-param> --><!-- <param-name>contextConfigLocation</param-name> --><!-- <param-value>classpath:ApplicationContext.xml --><!-- </param-value> --><!-- </context-param> --><!-- 日志记录 --><!-- <context-param> --><!-- 日志配置文件路径 --><!-- <param-name>log4jConfigLocation</param-name> --><!-- <param-value>classpath:log4j.properties</param-value> --><!-- </context-param> --><!-- <context-param> --><!-- 日志页面的刷新间隔 --><!-- <param-name>log4jRefreshInterval</param-name> --><!-- <param-value>6000</param-value> --><!-- </context-param> --><!-- <listener> --><!-- <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> --><!-- </listener> --><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list></web-app>



0 0
原创粉丝点击