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="${jdbc.driverClassName}"/>            <property name="url" value="${jdbc.url}"/>            <property name="username" value="${jdbc.username}"/>            <property name="password" value="${jdbc.password}"/>        </bean>    <bean id="sqlsessionFaction" class="org.mybatis.spring.SqlSessionFactoryBean">        <property name="dataSource" ref="dataSource"/>        <property name="mapperLocations" value="classpath:mappers/*.xml"/>    </bean>

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">        <property name="basePackage" value="com.gx.mappers"/>        <property name="sqlSessionFactoryBeanName" value="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="org.springframework.web.servlet.view.JstlView"/>        <property name="prefix" value="/WEB-INF/views/"/><!--设置JSP文件的目录位置-->        <property name="suffix" value=".jsp"/>        <property name="exposeContextBeansAsAttributes" value="true"/>    </bean>

    <!--文件上传-->    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">        <property name="defaultEncoding" value="UTF-8"/>        <property name="maxUploadSize" value="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>

原文地址:https://www.cnblogs.com/fengfeng21/p/12221659.html

时间: 2024-08-28 20:01:09

applicationContext.xml文件和dispatcher-servlet.xml文件和web.xml文件的相关文章

idea中添加web.xml配置文件与tomcat启动中遇到的web.xml文件找不到的问题

1,如何在idea中向war项目中添加web.xml的配置文件 idea通过maven创建war项目时没有指定是webapp导致创建出来的项目没有webapp的文件夹.其实war项目中都是在"项目名/src/main"目录下 只要在这个项目下创建webapp/WEB-INF/web.xml就行了 2,如果你没有把web.xml放在"项目名/src/main/webapp/WEB-INF/web.xml",这时tomcat启动就会报错: maven打包时错误信息:Er

Servlet容器Tomcat中web.xml中url-pattern的配置详解[附带源码分析]

前言 今天研究了一下tomcat上web.xml配置文件中url-pattern的问题. 这个问题其实毕业前就困扰着我,当时忙于找工作. 找到工作之后一直忙,也就没时间顾虑这个问题了. 说到底还是自己懒了,没花时间来研究. 今天看了tomcat的部分源码 了解了这个url-pattern的机制.  下面让我一一道来. tomcat的大致结构就不说了, 毕竟自己也不是特别熟悉. 有兴趣的同学请自行查看相关资料. 等有时间了我会来补充这部分的知识的. 想要了解url-pattern的大致配置必须了解

Servlet开发技术,创建,以及Servlet的配置,web.xml的配置

直接上图,不废话!!! 第一:首先在Eclipse的包资源管理器中,单机鼠标右键,在弹出的快捷键菜单中选择“新建”/Servlet命令,在弹出的对话框中输入新建的Servlet所在的包和类名,然后单击下一步, 我选择默认,Next 依旧默认,Next 注意事项,在创建web的工程的时候需要注意的是如下图,选择上web.xml这个按钮,因为Servlet需要配置一下web.xml这个文件,web.xml在web-inf这个文件下面 上图第二个箭头前面有个方括号,勾选上就可以自动创建好web.xml

Servlet(五)web.xml常用的一些配置

(1)lode-on-startup,该Servlet会在项目启动时被调用(主要调用起init方法,为安全着想,一般不应该为该Servlet建立URL映射),一般用作预处理一些数据,或者配合多线程建立定时任务 <servlet><pre name="code" class="html"><span style="font-family:Arial, Helvetica, sans-serif;"> </s

servlet获取并存储web.xml中context-param参数

在web.xml中定义了context-param,一般不会随意改动,所以在监听器中做一次处理,容器启动时读取并存储在Properties中,方便以后取值. SysProperties 类用于存储 context 键值: SystemListener 监听器类,处理 context-param 参数. /** * 用于存储参数键值 */ public final class SysProperties { private static SysProperties instance; privat

servlet urlpattern annotaion 需要web.xml增加点内容才能支持啊喂

<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_

Servlet中的配置 web.xml

url-pattern配置 可以为同一个Servlet配置多个url-pattern: <servlet> <servlet-name>DoGetPostDemo</servlet-name> <servlet-class>org.lyk.servlet.DoGetPostDemo</servlet-class> </servlet> <servlet-mapping> <servlet-name>DoGetP

servlet无法自动在web.xml中配置

在新建dynamic web project 时,dynamic web module version选择2.5. 原文地址:https://www.cnblogs.com/wxd136/p/9455819.html

Servlet中Web.xml文件的配置

1 定义头和根元素 部署描述符文件就像所有XML文件一样,必须以一个XML头开始.这个头声明可以使用的XML版本并给出文件的字符编码.DOCYTPE声明必须立即出现在此头之后.这个声明告诉服务器适用的servlet规范的版本(如2.2或2.3)并指定管理此文件其余部分内容的语法的DTD(Document Type Definition,文档类型定义).所有部署描述符文件的顶层(根)元素为web-app.请注意,XML元素不像HTML,他们是大小写敏感的.因此,web-App和WEB-APP都是不

对于JavaWeb项目中web.xml文件中Servlet的基本配置有一些小记录写在这里,并做参考,有新的及时更新

对于JavaWeb项目中web.xml文件中Servlet的基本配置有一些小记录写在这里,并做参考,有新的及时更新 <?xml version="1.0" encoding="UTF-8"?> <web-app> <!-- 在创建web项目时,若是系统自动生成,上面会有一串配置信息,因为不影响大局,这里没有列出--> <!-- 流程: 当在网页中使用/login时,发现不是网页,则会在web.xml找寻对应的名字,由url-