【applicationContext.xml文件和dispatcher-servlet.xml文件和web.xml文件】盛年不重来,一日难再晨,及时当勉励,岁月不待人。这篇文章主要讲述applicationContext.xml文件和dispatcher-servlet.xml文件和web.xml文件相关的知识,希望能为你提供帮助。
applicationContext.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:tx="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
< bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
< property name="locations">
< value> classpath:dadaSource.properties< /value>
< /property>
< /bean>
< bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
< property name="driverClassName" value="https://www.songbingjia.com/android/${jdbc.driverClassName}"/>
< property name="url" value="https://www.songbingjia.com/android/${jdbc.url}"/>
< property name="username" value="https://www.songbingjia.com/android/${jdbc.username}"/>
< property name="password" value="https://www.songbingjia.com/android/${jdbc.password}"/>
< /bean>
< bean id="sqlsessionFaction" class="org.mybatis.spring.SqlSessionFactoryBean">
< property name="dataSource" ref="dataSource"/>
< property name="mapperLocations" value="https://www.songbingjia.com/android/classpath:mappers/*.xml"/>
< /bean>
< bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
< property name="basePackage" value="https://www.songbingjia.com/android/com.gx.mappers"/>
< property name="sqlSessionFactoryBeanName" value="https://www.songbingjia.com/android/sqlsessionFaction"/>
< /bean>
< bean id="dataSourceTransation" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
< property name="dataSource" ref="dataSource"/>
< /bean>
< context:component-scan base-package="com.gx.controller"/>
< context:component-scan base-package="com.gx.mappers"/>
< context:component-scan base-package="com.gx.service"/>
< /beans>
dispatcher-servlet.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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
< !--此文件负责整个mvc中的配置-->
< !--启用spring的一些annotation -->
< context:annotation-config/>
< !-- 配置注解驱动 可以将request参数与绑定到controller参数上 -->
< mvc:annotation-driven/>
< !--静态资源映射-->
< !--本项目把静态资源放在了webapp的statics目录下,资源映射如下-->
< mvc:resources mapping="/css/**" location="/static/css/"/>
< mvc:resources mapping="/js/**" location="/static/js/"/>
< mvc:resources mapping="/image/**" location="/static/image/"/>
< mvc:default-servlet-handler /> < !--这句要加上,要不然可能会访问不到静态资源,具体作用自行百度-->
< !-- 对模型视图名称的解析,即在模型视图名称添加前后缀(如果最后一个还是表示文件夹,则最后的斜杠不要漏了) 使用JSP-->
< !-- 默认的视图解析器 在上边的解析错误时使用 (默认使用html)- -->
< bean id="defaultViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
< property name="viewClass" value="https://www.songbingjia.com/android/org.springframework.web.servlet.view.JstlView"/>
< property name="prefix" value="https://www.songbingjia.com/WEB-INF/views/"/> < !--设置JSP文件的目录位置-->
< property name="suffix" value="https://www.songbingjia.com/android/.jsp"/>
< property name="exposeContextBeansAsAttributes" value="https://www.songbingjia.com/android/true"/>
< /bean>
< !--文件上传-->
< bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
< property name="defaultEncoding" value="https://www.songbingjia.com/android/UTF-8"/>
< property name="maxUploadSize" value="https://www.songbingjia.com/android/3000000"/>
< /bean>
< !-- 自动扫描装配 -->
< context:component-scan base-package="com.gx.controller"/>
< /beans>
web.xml文件
< ?xml version="1.0" encoding="UTF-8"?>
< web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
< display-name> Archetype Created Web Application< /display-name>
< !--welcome pages-->
< welcome-file-list>
< welcome-file> index.jsp< /welcome-file>
< /welcome-file-list>
< !--配置springmvc DispatcherServlet-->
< servlet>
< servlet-name> springMVC< /servlet-name>
< servlet-class> org.springframework.web.servlet.DispatcherServlet< /servlet-class>
< init-param>
< !--配置dispatcher.xml作为mvc的配置文件-->
< param-name> contextConfigLocation< /param-name>
< param-value> /WEB-INF/dispatcher-servlet.xml< /param-value>
< /init-param>
< load-on-startup> 1< /load-on-startup>
< async-supported> true< /async-supported>
< /servlet>
< !--< servlet> -->
< !--< servlet-name> EmpServlet< /servlet-name> -->
< !--< servlet-class> com.gx.filter.EmpServlet< /servlet-class> -->
< !--< /servlet> -->
< servlet-mapping>
< servlet-name> springMVC< /servlet-name>
< url-pattern> /< /url-pattern>
< /servlet-mapping>
< !--把applicationContext.xml加入到配置文件中-->
< context-param>
< param-name> contextConfigLocation< /param-name>
< param-value> /WEB-INF/applicationContext.xml< /param-value>
< /context-param>
< context-param>
< param-name> log4jConfigLocation< /param-name>
< param-value> /WEB-INF/log4j.properties< /param-value>
< /context-param>
< listener>
< listener-class> org.springframework.web.context.ContextLoaderListener< /listener-class>
< /listener>
< /web-app>
推荐阅读
- Android Chart Views
- myBatis mapper接口方法重载问题
- SSMAppFileUtils
- Android日期时间控件DatePickerDialog和TimePickerDialog
- 警告: Hessian/Burlap: 'com.github.pagehelper.Page' is an unknown class in WebappClassLoader(示例
- 一加6安卓10降级安卓9稳定版并且禁用系统更新教程
- VS 2019开发APP多界面开发
- Android : SQLite 版学生系统
- Appnium 环境搭建