設定手順の概要
spring-session redis 設定ライフを開始する 4 つの簡単な手順
1. pom.xml jar 依存関係を追加します
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> .... <properties> <version.spring-session>1.2.2.RELEASE</version.spring-session> <!--不兼容 1.7.4.RELEASE --> <version.spring-data-redis>1.7.1.RELEASE</version.spring-data-redis> </properties> <dependencies> .... <dependency> <groupId>org.springframework.session</groupId> <artifactId>spring-session</artifactId> <version>${version.spring-session}</version> </dependency> <dependency> <groupId>org.springframework.session</groupId> <artifactId>spring-session-data-redis</artifactId> <version>${version.spring-session}</version> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-redis</artifactId> <version>${version.spring-data-redis}</version> </dependency> .... </dependencies> </project>
2. web.xml に springSessionRepositoryFilter 設定を追加します
rreee-3.クラスター.xml ダウンロード<?xml version="1.0" encoding="UTF-8"?> <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_0.xsd"> ... <!-- spring-session config --> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath*:spring-session-cluster.xml </param-value> </context-param> <!-- 这个filter 要放在第一个 --> <filter> <filter-name>springSessionRepositoryFilter</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>springSessionRepositoryFilter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>ERROR</dispatcher> </filter-mapping> ... </web-app>4. redis-cluster.properties ダウンロード
<?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:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util" 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/util http://www.springframework.org/schema/util/spring-util.xsd "> <context:annotation-config /> <util:properties id="redis" location="classpath:redis-cluster.properties"></util:properties> <!-- RedisHttpSessionConfiguration --> <bean class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration" /> <!--JedisConnectionFactory --> <bean class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"> <constructor-arg index="0"> <!-- since spring-data-redis 1.7 --> <bean class="org.springframework.data.redis.connection.RedisClusterConfiguration"> <constructor-arg index="0"> <set> <value>#{redis['redis.redisClusterConfiguration.clusters']}</value> </set> </constructor-arg> <!-- 用于 redis.clients.jedis.JedisCluster.JedisCluster(Set<HostAndPort>, int, int, GenericObjectPoolConfig) 第三个参数 maxRedirections 默认值是5 一般当此值设置过大时,容易报:Too many Cluster redirections --> <property name="maxRedirects" value="#{redis['redis.redisClusterConfiguration.maxRedirects']}" /> </bean> </constructor-arg> <constructor-arg index="1"> <bean class="redis.clients.jedis.JedisPoolConfig"> <property name="maxIdle" value="#{redis['redis.jedisPoolConfig.MaxIdle']}" /> <property name="testOnBorrow" value="#{redis['redis.jedisPoolConfig.testOnBorrow']}" /> <property name="testOnReturn" value="#{redis['redis.jedisPoolConfig.testOnReturn']}" /> <!-- 新版jedis 不支持这个参数了 --> <!-- <property name="maxWait" value="#{redis['redis.jedisPoolConfig.MaxWait']}" /> --> <!-- <property name="maxActive" value="#{redis['redis.jedisPoolConfig.MaxActive']}" /> --> </bean> </constructor-arg> </bean> </beans>
声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事
アサシンのクリードシャドウズ:シーシェルリドルソリューション
3週間前ByDDD
Atomfallのクレーンコントロールキーカードを見つける場所
3週間前ByDDD
<🎜>:Dead Rails-すべての課題を完了する方法
4週間前ByDDD
Atomfall Guide:アイテムの場所、クエストガイド、およびヒント
1 か月前ByDDD

ホットツール

Safe Exam Browser
Safe Exam Browser は、オンライン試験を安全に受験するための安全なブラウザ環境です。このソフトウェアは、あらゆるコンピュータを安全なワークステーションに変えます。あらゆるユーティリティへのアクセスを制御し、学生が無許可のリソースを使用するのを防ぎます。

AtomエディタMac版ダウンロード
最も人気のあるオープンソースエディター

SAP NetWeaver Server Adapter for Eclipse
Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

SublimeText3 中国語版
中国語版、とても使いやすい

SecLists
SecLists は、セキュリティ テスターの究極の相棒です。これは、セキュリティ評価中に頻繁に使用されるさまざまな種類のリストを 1 か所にまとめたものです。 SecLists は、セキュリティ テスターが必要とする可能性のあるすべてのリストを便利に提供することで、セキュリティ テストをより効率的かつ生産的にするのに役立ちます。リストの種類には、ユーザー名、パスワード、URL、ファジング ペイロード、機密データ パターン、Web シェルなどが含まれます。テスターはこのリポジトリを新しいテスト マシンにプルするだけで、必要なあらゆる種類のリストにアクセスできるようになります。

ホットトピック
Gmailメールのログイン入り口はどこですか?
7685
15


Java チュートリアル
1639
14


CakePHP チュートリアル
1393
52


Laravel チュートリアル
1287
25


PHP チュートリアル
1229
29

