【Spring實戰】----springMVC4.3.2的配置
一、簡單說明
本篇springMVC的配置涉及到springMVC配置、sitemesh配置、log4j2的配置
二、相關庫檔案
根據myeclipse中建立gradle web專案建立完成後(建議使用idea進行,本系列也已用idea進行分析),在build.gradle中新增下面庫檔案
- apply plugin: 'java'
- apply plugin: 'war'
- sourceCompatibility = 1.5
- version = '1.0'
- jar {
- manifest {
-
attributes 'Implementation-Title': 'Gradle Quickstart',
- 'Implementation-Version': version
- }
- }
- repositories {
- jcenter()
- mavenCentral()
- }
- dependencies {
- compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
-
testCompile group: 'junit', name: 'junit', version: '4.+'
- //servlet
- providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0' //在配置apply plugin: 'war'才可用
- runtime("jstl:jstl:1.2")
- //spring
- def springVersion = "4.3.2.RELEASE";
- compile "org.springframework:spring-context:$springVersion"
-
compile "org.springframework:spring-core:$springVersion"
- compile "org.springframework:spring-webmvc:$springVersion"
- //sitemesh
- compile "org.sitemesh:sitemesh:3.0.0"
- //log4j2
- def log4j_version = "2.2";
- compile "org.apache.logging.log4j:log4j-api:$log4j_version"
- compile "org.apache.logging.log4j:log4j-core:$log4j_version"
- compile "org.apache.logging.log4j:log4j-slf4j-impl:$log4j_version"
- }
- test {
- systemProperties 'property': 'value'
- }
- uploadArchives {
- repositories {
- flatDir {
- dirs 'repos'
- }
- }
- }
三、web.xml
雖然spring從3.1版本後可以採用Java配置的方式配置springMVC(具體可參見《spring實戰第四版》)。但本文還是採用傳統的web.xml配置方式
- <?xmlversion="1.0"encoding="UTF-8"?>
- <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">
- <display-name>SpringMango</display-name>
- <!--==================== LISTENER Spring容器====================-->
- <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>
- </listener>
- <!-- 防止記憶體洩漏 -->
- <listener>
- <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
- </listener>
- <!--==================== SERVLET Spring MVC====================-->
- <servlet>
- <servlet-name>Mango</servlet-name>
- <servlet-class>
- org.springframework.web.servlet.DispatcherServlet
- </servlet-class>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>Mango</servlet-name>
- <url-pattern>/</url-pattern>
- </servlet-mapping>
- <!--START 設定字元編碼過濾器-->
- <filter>
- <description>字符集過濾器</description>
- <filter-name>encodingFilter</filter-name>
- <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
- <init-param>
- <description>字符集編碼</description>
- <param-name>encoding</param-name>
- <param-value>UTF-8</param-value>
- </init-param>
- </filter>
- <filter-mapping>
- <filter-name>encodingFilter</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- <!--END 設定字元編碼過濾器-->
-
相關推薦
【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 boot】2.0 配置@cacheable 自定義序列化方式 快取資料到redis
一·背景描述 spring 的 @cacheable 已成為我們比較常用的快取資料的方式,但是把非String物件快取到redis後在使用RedisDesktopManager等軟體檢視快取的資料的時候 展示的是HEX 資料,觀察起來比較不方便,所以我們這裡自定義了Fas
【Spring-Security】【2】DelegatingFilterProxy
pat security clas 添加 chain let XML org mapping Spring Security 對我們應用的影響是通過一系列的 ServletRequest 過濾器實現的。 Spring Security 使用了 o.s.web.filter
【spring Boot】2.在Myecplise上把spring Boot項目打包 war包和jar包
aps let failed htm 報錯 聲明 執行 spa oss ========================================================第一部分=========================================
【spring boot】3.spring boot項目,綁定資源文件為bean並使用
display fig 屬性綁定 factor pin none rand actor tag 整個例子的結構目錄如下: 1.自定義一個資源文件 com.sxd.name = 申九日木 com.sxd.secret = ${random.value} com.sx
【Spring Boot 】2、Spring 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