Recording SSM session distributed cross-domain-Redis scheme

Source: Internet
Author: User
Tags date format converter i18n redis

Use Redis to solve:

Redis is installed by default

Introducing Jar Packs

Group ' Org.springframework.session ' name ' Spring-session-data-redis ' version ' 1.3.1.RELEASE '//https://mvnrepository.com/artifact/biz.paluch.redis/lettuce
Group' Biz.paluch.redis 'name' lettuce'version' 4.4.2.Final
 '

Redis.properties

Redis_hostname = localhost
redis_port = 6379
Redis_password =
redis_timeout = 3600
redis.maxidle=
redis.maxactive=600
redis.maxwait=1000
redis.testonborrow=true
Spring.xml
<?xml version= "1.0" encoding= "UTF-8"?> <beans "xmlns=" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" 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/context Http://www.springframework.org/schema/context /spring-context-3.0.xsd "> <!--annotation support--> <context:annotation-config/> <!--boot component scan, excluding @control The Ler component, which is scanned by the SPRINGMVC profile .service--> <context:component-scan base-package= "com.xping" > <context: Exclude-filter type= "Annotation" expression= "Org.springframework.stereotype.Controller"/> </context: Component-scan> <!--Introducing property files (multiple)--> <bean id= "Propertyconfigurer" class= "ORG.SPRINGFRAMEWORK.BEANS.FAC" Tory.config.PropertyPlaceholderConfigurer "> <property name=" lOcations "> <list> <value>classpath:dbConfig.properties</value> <value>classpath:redis.properties</value> </list> </property> </b ean> <import resource= "Spring-mybatis.xml"/> <import "resource=" Spring-redis.xml/> cl ass= "Org.springframework.web.servlet.view.BeanNameViewResolver"/> </beans>
Spring-mvc.xml
<?xml version= "1.0" encoding= "UTF-8"?> <beans xmlns= "Http://www.springframework.org/schema/beans" XMLNS:MV C= "Http://www.springframework.org/schema/mvc" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" Xmlns:co ntext= "Http://www.springframework.org/schema/context" xsi:schemalocation= "Http://www.springframework.org/schema
	/MVC http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd Http://www.springframework.org/schema/beans
	Http://www.springframework.org/schema/beans/spring-beans-3.2.xsd Http://www.springframework.org/schema/context Http://www.springframework.org/schema/context/spring-context-3.2.xsd "> <!--open annotations--> <mvc:annotation-d Riven/> <!--SPRINGMVC when the JSON value is resolved--> <mvc:annotation-driven> &LT;MVC:MESSAGE-CONVERTERS&G
            T <bean class= "Org.springframework.http.converter.StringHttpMessageConverter" > <property name= "Supp"
        Ortedmediatypes ">            <list> <value>application/json;charset=UTF-8</value>
    </list> </property> </bean> </mvc:message-converters> </mvc:annotation-driven> <!--automatically scans all classes under the controller package so that it considers the controller of spring MVC--> <context:component-scan Base-package= "Com.xping.controller"/> <!--defines the prefix of the file that jumps, and the view mode configuration--> <bean class= "org.springframework. Web.servlet.view.InternalResourceViewResolver "> <!--path prefix--> <property name=" prefix "value="/w

    eb-inf/views/"/> < suffix of the path--> <property name=" suffix "value=". jsp "/> </bean> <!--file Upload configuration--> <bean id= "Multipartresolver" class= " Org.springframework.web.multipart.commons.CommonsMultipartResolver "> <!--default encoding--> <property n Ame= "defaultencoding" value= "UTF-8"/> <!--upload file size limit to 31m,31*1024*10--> <property name= "maxuploadsize" value= "32505856"/> <!--maximum value in memory--> Rty name= "Maxinmemorysize" value= "4096"/> </bean> <!--date format converter--> <bean id= "Conversionservi Ce "class=" Org.springframework.context.support.ConversionServiceFactoryBean > <property name= "Converters" &G
            T <set> <bean class= "Com.xping.utils.StringToDateConverter" > <constructor -arg name= "Datepattern" value= "Yyyy-mm-dd"/> </bean> </set> </proper ty> </bean> <bean id= "Messagesource" class= "Org.springframework.context.support.ResourceBun" Dlemessagesource "> <property name=" defaultencoding value= "UTF-8"/> <property name= "UseCodeAsD Efaultmessage "value=" true "/> <!--internationalized resource file name--> <property name=" Basenames "> &L T;list>
                <value>language.about</value> <value>language.header</value>
                <value>language.login</value> <value>language.footer</value> <value>language.page_404</value> <value>language.home</value> & lt;/list> </property> </bean> <mvc:interceptors> <!--<mvc:interceptor& gt;--> <!--<mvc:mapping path= "/**"/>--> <!--<bean class= "Com.xpingg.interceptor.CSRFI Nterceptor "/>--> <!--</mvc:interceptor>--> <!--internationalization Operation Interceptor if based on (Session/cookie) required configuration --> <mvc:interceptor> <mvc:mapping path= "/**"/> <bean class= "ORG.SPRINGF"
            Ramework.web.servlet.i18n.LocaleChangeInterceptor "/> </mvc:interceptor> <mvc:interceptor> <!--match is URL path, if not configured or/**, will intercept all controller--> <!--intercept the go suffix do not intercept the py suffix--> <mvc:mapping path= "/*.go"
            /> <!--resources do not intercept--> <!--<mvc:exclude-mapping path= "/**/*login*"/>-->
            <!--<mvc:exclude-mapping path= "/**/*login*"/>--> <!--/register and/login do not need to intercept--> <!--<mvc:exclude-mapping path= "/index.py"/>--> <bean class= "Com.xping.interceptor.LoginInte Rceptor > <!--defines the redirect to the default login processing page after blocking--> <property name= "Defultlogin value="/noau th.py "/> </bean> </mvc:interceptor> <!--When multiple interceptors are set, the Prehandle method is called sequentially, and then the Posthandle and Aftercompletion methods for each interceptor--> </mvc:interceptors> <!--acceptheaderlocaleresolver configuration, because accep Theaderlocaleresolver is the default language zone parser, not configured or can I use my modified parser--> <bean id= "Localeresolver" Org.springframework.web.servlet.i18n.SessionLocAleresolver "> <property name=" Defaultlocale "value=" Zh_cn "/> </bean> <!--leave static resources to the default serv Let processing--> <mvc:default-servlet-handler/> <!--important. Inject your swaggerconfig configuration class into--> <bean class= "Com.xping.config.SwaggerConfig"/> </beans>
Spring-redis.xml
<?xml version= "1.0" encoding= "UTF-8"?> <beans xmlns= "Http://www.springframework.org/schema/beans" Xmlns:xs
       I= "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "Http://www.springframework.org/schema/beans Http://www.springframework.org/schema/beans/spring-beans.xsd "> <!--session settings--> <bean class=" org. Springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration "> <property Name= "Maxinactiveintervalinseconds" value= "3600"/> </bean> <!--redis Connection pool--> <bean id= "Poolc
        Onfig "class=" Redis.clients.jedis.JedisPoolConfig > <property name= "maxidle" value= "${redis.maxidle}"/> <property name= "Maxtotal" value= "${redis.maxactive}"/> <property name= "Maxwaitmillis" value= edis.maxwait} "/> <property name= testonborrow" value= "${redis.testonborrow}"/> </bean> & lt;!
    --Redis Connection Factory--><bean id= "ConnectionFactory" class= "Org.springframework.data.redis.connection.jedis.JedisConnectionFactory" > <property name= "hostName" value= "${redis_hostname}"/> <property name= "Port value=" ${redis_p ORT} "/> <property name=" password "value=" ${redis_password} "/> <property name=" Timeout "value=" ${redis_timeout} "/> <property name= poolconfig" ref= "Poolconfig"/> </bean> <!--session-- > <bean class= "org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory"/> <!--in use class resolves rediscache.jedisconnectionfactory static injection, which enables MyBatis to implement a third-party cache--> <bean id= "Rediscachetransfer" class= " Com.xping.utils.RedisCache.RedisCacheTransfer "> <property name=" jedisconnectionfactory "ref=" connectionfact Ory "/> </bean> <!--Configure Redis string run environment--> <bean id=" Stringredisserializer "class=" Org.springfram Ework.data.redis.serializer.StringRedisSerializEr "/> <!--configuration redistemplate--> <bean id=" redistemplate "class=" org.springframework.data.redis.core.Re Distemplate "> <property name=" connectionfactory "ref=" ConnectionFactory "/> <property name=" key
    Serializer "ref=" Stringredisserializer "/> <property name=" ValueSerializer "ref=" StringRedisSerializer "/> </bean> </beans>
Xml
<?xml version= "1.0" encoding= "UTF-8"?> <web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" XM lns= "Http://java.sun.com/xml/ns/javaee" xmlns:web= "Http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" xs i:schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id= "webap p_id "version=" 3.0 "> <display-name>AoShop</display-name> <servlet> <servlet-name >DruidStatView</servlet-name> <servlet-class>com.alibaba.druid.support.http.statviewservlet</ servlet-class> <init-param> <param-name>allow</param-name> <param- value>127.0.0.1</param-value> </init-param> <init-param> &LT;PARAM-NAME&G
        T;deny</param-name> <param-value>192.168.1.118</param-value> </init-param> <!--in StatviewserlveT output HTML page, there is a function is reset all, after performing this operation, will cause all counters to clear zero, re-count--> <init-param> <param-name>reset Enable</param-name> <param-value>false</param-value> </init-param> ;init-param> <param-name>loginUsername</param-name> <param-value>lmy</para m-value> </init-param> <init-param> <param-name>loginpassword</param-n ame> <param-value>165177</param-value> </init-param> </servlet> ;servlet-mapping> <servlet-name>DruidStatView</servlet-name> <url-pattern>/druid/*&lt ;/url-pattern> </servlet-mapping> <!--the Spring service layer's configuration file--> <context-param> <p Aram-name>contextconfiglocation</param-name> <param-value>classpath:spring.xml</param-value > &LT;/CONTEXT-PARAM&GT <!--Spring Listener--> <listener> <listener-class>org.springframework.web.context.contextloaderl
        Istener</listener-class> </listener> <!--prevent spring memory overflow listeners, such as quartz--> <listener> <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class> </
        Listener> <!--Front Controller--> <servlet> <servlet-name>SpringMVC</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!--loading SPRINGMV
            C Configuration Q-file--> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-mvc.xml</param-value> </init-param> <load-on-startup& 
    Gt;1</load-on-startup> <async-supported>true</async-supported> </servlet> <!-- The first: *.action. ACtion end of the resolution by the Dispatcherservlet of the second:/All Access addresses are resolved by Dispatcherservlet, for static file resolution needs to configure the Dispatcherservlet parsing. This way you can implement the restful style of the URL of the third:/*, this configuration is not, use this configuration, the final to forward to a JSP page, still will be dispatcherservlet to resolve JSP address, it can not be based on JSP page to find handler,  Will complain--> <servlet-mapping> <servlet-name>SpringMVC</servlet-name> <!--can also be configured here *.do form--> <url-pattern>/</url-pattern> </servlet-mapping> <!--browsers do not support Put,delet E-et method, which converts/xxx?_method=delete to standard HTTP Delete methods--> <filter> &LT;FILTER-NAME&GT;HIDDENHTTPME Thodfilter</filter-name> <filter-class>org.springframework.web.filter.hiddenhttpmethodfilter</ filter-class> </filter> <filter-mapping> <filter-name>hiddenhttpmethodfilter</filt
        er-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>/index.jsp</welcome-file&Gt </welcome-file-list> <!--Configure the spring character encoding filter--> <filter> <filter-name>encodingfilter </filter-name> <filter-class>org.springframework.web.filter.characterencodingfilter</ filter-class> <init-param> <param-name>encoding</param-name> <para m-value>utf-8</param-value> </init-param> <init-param> <param-name> Forceencoding</param-name> <param-value>true</param-value> </init-param> & lt;/filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pa Ttern>/*</url-pattern> </filter-mapping> <!--error Page Setup--> <error-page> <e Rror-code>403</error-code> <location>/WEB-INF/views/page_404.jsp</location> </error-pa
Ge> <error-page>        <error-code>404</error-code> <location>/WEB-INF/views/page_404.jsp</location> </error-page> <error-page> <error-code>500</error-code> <location>/web-i nf/views/page_404.jsp</location> </error-page> <filter> <filter-name>springsessio Nrepositoryfilter</filter-name> <filter-class>org.springframework.web.filter.delegatingfilterproxy& lt;/filter-class> </filter> <filter-mapping> <filter-name>springsessionrepositoryfilt Er</filter-name> <url-pattern>/*</url-pattern> <dispatcher>request</dispatcher&
        Gt
 <dispatcher>ERROR</dispatcher> </filter-mapping> </web-app>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.