1. 程式人生 > >【Spring實戰】----springMVC4.3.2的配置

【Spring實戰】----springMVC4.3.2的配置

一、簡單說明

本篇springMVC的配置涉及到springMVC配置、sitemesh配置、log4j2的配置

二、相關庫檔案

根據myeclipse中建立gradle web專案建立完成後(建議使用idea進行,本系列也已用idea進行分析),在build.gradle中新增下面庫檔案

  1. apply plugin: 'java'  
  2. apply plugin: 'war'  
  3. sourceCompatibility = 1.5  
  4. version = '1.0'
  5. jar {  
  6.     manifest {  
  7.         attributes 'Implementation-Title': 'Gradle Quickstart',  
  8.                    'Implementation-Version': version  
  9.     }  
  10. }  
  11. repositories {  
  12.     jcenter()  
  13.     mavenCentral()  
  14. }  
  15. dependencies {  
  16.     compile group: 'commons-collections', name: 'commons-collections', version: '3.2'  
  17.     testCompile group: 'junit', name: 'junit', version: '4.+'  
  18.     //servlet  
  19.     providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'    //在配置apply plugin: 'war'才可用  
  20.     runtime("jstl:jstl:1.2")  
  21.     //spring  
  22.     def springVersion = "4.3.2.RELEASE";   
  23.     compile "org.springframework:spring-context:$springVersion"    
  24.     compile "org.springframework:spring-core:$springVersion"    
  25.     compile "org.springframework:spring-webmvc:$springVersion"  
  26.     //sitemesh  
  27.     compile "org.sitemesh:sitemesh:3.0.0"  
  28.     //log4j2  
  29.     def log4j_version = "2.2";  
  30.     compile "org.apache.logging.log4j:log4j-api:$log4j_version"  
  31.     compile "org.apache.logging.log4j:log4j-core:$log4j_version"  
  32.     compile "org.apache.logging.log4j:log4j-slf4j-impl:$log4j_version"  
  33. }  
  34. test {  
  35.     systemProperties 'property': 'value'  
  36. }  
  37. uploadArchives {  
  38.     repositories {  
  39.        flatDir {  
  40.            dirs 'repos'  
  41.        }  
  42.     }  
  43. }  

三、web.xml

雖然spring從3.1版本後可以採用Java配置的方式配置springMVC(具體可參見《spring實戰第四版》)。但本文還是採用傳統的web.xml配置方式

  1. <?xmlversion="1.0"encoding="UTF-8"?>
  2. <web-appxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"id="WebApp_ID"version="3.0">
  3.   <display-name>SpringMango</display-name>
  4.     <!--==================== LISTENER Spring容器====================-->
  5.     <context-param>
  6.       <param-name>contextConfigLocation</param-name>
  7.       <param-value>classpath*:applicationContext-*.xml</param-value>
  8.     </context-param>
  9.     <listener>
  10.       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  11.     </listener>
  12.     <!-- 防止記憶體洩漏 -->
  13.     <listener>
  14.         <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
  15.     </listener>
  16.     <!--==================== SERVLET Spring MVC====================-->
  17.     <servlet>
  18.         <servlet-name>Mango</servlet-name>
  19.         <servlet-class>
  20.             org.springframework.web.servlet.DispatcherServlet  
  21.         </servlet-class>
  22.         <load-on-startup>1</load-on-startup>
  23.     </servlet>
  24.     <servlet-mapping>
  25.         <servlet-name>Mango</servlet-name>
  26.         <url-pattern>/</url-pattern>
  27.     </servlet-mapping>
  28.     <!--START 設定字元編碼過濾器-->
  29.     <filter>
  30.         <description>字符集過濾器</description>
  31.         <filter-name>encodingFilter</filter-name>
  32.         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  33.         <init-param>
  34.             <description>字符集編碼</description>
  35.             <param-name>encoding</param-name>
  36.             <param-value>UTF-8</param-value>
  37.         </init-param>
  38.     </filter>
  39.     <filter-mapping>
  40.         <filter-name>encodingFilter</filter-name>
  41.         <url-pattern>/*</url-pattern>
  42.     </filter-mapping>
  43.     <!--END 設定字元編碼過濾器-->
  44. 相關推薦

    Spring實戰----springMVC4.3.2配置

    一、簡單說明 本篇springMVC的配置涉及到springMVC配置、sitemesh配置、log4j2的配置 二、相關庫檔案 根據myeclipse中建立gradle web專案建立完成後(建議使用idea進行,本系列也已用idea進行分析),在

    Spring實戰----spring security4.1.3配置以及踩過的坑

    一、所需的庫檔案//spring-security compile 'org.springframework.security:spring-security-web:4.1.3.RELEASE' compile 'org.springframework.security

    Spring實戰----Spring事務管理配置解析

    上篇說了aop的配置,並且說了Spring事務管理是基於aop的,那麼Spring宣告式事務的配置就有兩種方式:XML配置及註解配置不多說,直接看配置檔案一、配置檔案applicationContext-transaction.xml<?xml version="1.0

    Spring實戰Spring註解配置工作原理原始碼解析

    一、背景知識在【Spring實戰】Spring容器初始化完成後執行初始化資料方法一文中說要分析其實現原理,於是就從原始碼中尋找答案,看原始碼容易跑偏,因此應當有個主線,或者帶著問題、目標去看,這樣才能最大限度的提升自身程式碼水平。由於上文中大部分都基於註解進行設定的(Spri

    Spring實戰----Spring配置檔案的解析

    一、背景知識Spring的核心的核心就是bean的配置及管理,至Spring最新發布的版本4.3.2已經有三種方式可以配置bean:1)在XML中進行顯示配置2)在Java中進行顯示配置3)隱式的bean發現機制和自動裝配上述三種配置不展開說明,而且目前用的較多的是第3種(當

    Spring Security七、RememberMe配置

    rop 基於 fig mep alias tom 保存 統一 source 一、概述 RememberMe 是指用戶在網站上能夠在 Session 之間記住登錄用戶的身份的憑證,通俗的來說就是用戶登陸成功認證一次之後在制定的一定時間內可以不用再輸入用戶名和密碼進行自動登錄

    新手實戰redhat 6.2 升級openSSH (配合安裝GCC,升級openSSL)

    致謝:CSDN;linux公社-編輯Linux、wyb7821、wangyan以及未列出的網際網路前輩。 背景:公司的SFTP實體機(RedHat 6.2 x86_64)被綠盟掃描出openSSH工具有漏洞,需要進行升級。登入到伺服器一看悲劇了,沒有GCC編譯器!原來5年前

    Spring 系列1. 搭建和配置Spring與jdbc整合的環境

    配置資料來源 <!-- 配置結點,可以使用佔位符 --> <context:property-placeholder location=“classpath:jdbc.properties”/> <bean id="dataSource" class="org.apach

    Spring實戰----原始碼解析SessionFactory及Session的管理及getCurrentSession的使用

    在上一篇Hibernate5整合中當使用sessionFactory.getCurrentSession()時會報錯Could not obtain transaction-synchronized Session for current thread,本篇就從原始碼角度

    Spring-Ldap環境準備及配置

    環境準備(Maven專案為例) spring-ldap-core(Spring LDAP庫)(必須) spring-core(框架內部使用的其他實用程式類) spring-beans

    Ruby on Rails實戰3.2 配置資料庫以及資料庫操作知識

    1、建立一個database mysql我們已經在1.3節安裝過了。連線遠端,在專案目錄下連線mysql,建立一個database資料庫。如果你在1.3節啟動專案時碰到了mysql錯誤並且解決了,那可以跳過1、2步,因為你已經配置好了。 vagrant@vagrant-ubunt

    spring boot2.0 配置@cacheable 自定義序列化方式 快取資料到redis

    一·背景描述  spring 的  @cacheable 已成為我們比較常用的快取資料的方式,但是把非String物件快取到redis後在使用RedisDesktopManager等軟體檢視快取的資料的時候 展示的是HEX 資料,觀察起來比較不方便,所以我們這裡自定義了Fas

    Spring-Security2DelegatingFilterProxy

    pat security clas 添加 chain let XML org mapping Spring Security 對我們應用的影響是通過一系列的 ServletRequest 過濾器實現的。 Spring Security 使用了 o.s.web.filter

    spring Boot2.在Myecplise上把spring Boot項目打包 war包和jar包

    aps let failed htm 報錯 聲明 執行 spa oss ========================================================第一部分=========================================

    spring boot3.spring boot項目,綁定資源文件為bean並使用

    display fig 屬性綁定 factor pin none rand actor tag 整個例子的結構目錄如下: 1.自定義一個資源文件 com.sxd.name = 申九日木 com.sxd.secret = ${random.value} com.sx

    Spring Boot 2Spring Boot CLI

    pac sam nbsp ref tps 項目 gin 1.8 com 1.配置Spring的環境變量在環境變量Path 添加: D:\Program Files\spring-boot-cli-1.5.8.RELEASE-bin\spring-1.5.8.RELEASE\

    spring boot配置文件 application.properties 屬性解析

    date hiberna mage ida str 數據丟失 art rop 就會 1.JPA命名策略 spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.DefaultNamingStrategy 有兩種值

    解憂雜貨店靜態路由基礎配置--華為數通R&S實驗漫載(3

    華為數通 路由與交換 華為認證 靜態路由 實驗拓撲 網絡規劃 設備 IP地址 網關 PC1 192.168.1.1/24 192.168.1.254/24 PC2 192.168.2.1/24 192.168.2.254/24 AR1-G0/0/0 10.1.12.1

    Spring Boot(19)、Spring Boot嵌入式Servlet容器自動配置原理

        其中EmbeddedServletContainerAutoConfiguration是嵌入式Servlet容器的自動配置類,該類在spring-boot-autoconfigure-xxx.jar中的web模組可以找到。 @AutoConfig

    Spring Boot(18)、Spring Boot配置嵌入式Servlet容器

    Spring Boot預設使用Tomcat作為嵌入式的Servlet容器,只要引入了spring-boot-start-web依賴,則預設是用Tomcat作為Servlet容器: 1、定製和修改Servlet容器的相關配置 1)、修改和server有關的配置(ServerProper