今日は、フレームワークの統合中に遭遇した問題を記録しましょう。
1. Redisを使用してセッション共有を実装する場合、プロジェクトの開始レポート「SpringsessionRepositoryFilter」という名前のBeanが定義されています。
2。キャッシュツールクラスを呼び出すと、注入されたジェダイスプールはヌルです(スプリングスキャンに関連する詳細なエラー)
わかりました、統合したファイルを追加し始めました
pom.xmlはJARパッケージに依存します
<! - 春のセッション開始 - > <依存関係> <groupId> redis.clients </groupid> <artifactid> jedis </artifactid> <version> 2.9.0 </version> </dependency> <dependency> <groupid> org.springframework.session </groupid> <artifactid </artificid> <バージョン> 1.2.1.Release </version> </dependency>
web.xml構成
<?xml version = "1.0" encoding = "utf-8"?> <web-app xmlns:xsi = "http://www.w3.org/2001/xmlschema-instance" xmlns = "http://java.sun.com/xml/nns/javaee xsi:schemalocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/ns/javaee/web-app_0.0.xsd" "> <param-name> contextconfiglocation </param-name> <param-value> classpath:spring-cfg.xml </param-value> </context-param> <! - フィルターヘッドに配置されたセッションフィルター - > <フィルター> <フィルター> <フィルター> <フィルター> <フィルター> <filter-class> org.springframework.web.filter.delegatingfilterproxy </filter-class> </filter> <filter-mapping> <filter-name> springsessionRepositoryFilter </filter-name> <url-pattern>/*</url-pattern> </フィルターマッピング> <! <filter-name> encodingfilter </filter-name> <filter-class> org.springframework.web.filter.characterencodingfilter </filter-class> <async-supported> true </async-supported> <init-param> <init-param> <paramoune> encoding </name> </param-value> <param-value> </init-param> </filter> <filter-mapping> <filter-name> encodingfilter </filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <! - springリスナー - > <リスナー> org.springframework.web.context.contextlodexedextodextolylistener </</</</</リスナー> MVC-> <Servlet> <Servlet-Name> springMVC </servlet-name> <servlet-class> org.springframework.web.servlet.dispatcherservlet </servlet-class> <init-param> <param-name> contextconfiglocation </paramue> class-mvc.xml> <load-on-startup> 1 </load-on-startup> <async-supported> true </async-supported> </servlet> <servlet-mapping> <servlet-name> springmvc </servlet-name> <url-pattern>/</url-pattern> <url-pattern>/static/*</url-pattern> </servet-mapping> - > </web-app>
spring-cfg.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:aop = "http://www.springframework.org/schema/aop" xmlns:tx = " xmlns:util = "http://www.springframework.org/schema/util" xsi:schemalocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframeworkwork/ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd "> <! - ファセットプログラミングの自動プロキシを開きます - > <! - アノテーションをスキャンしてBeanを生成します - > <コンテキスト:annotation-config/> <context:component-scansaber-package = "com.zyt"> <context:explude-filter type = "annotation" expression = "org.springframework.tretype.controller"/>> < id = "propertyconfigurer"> <property name = "locations"> <list> <value> classpath:jdbc.properties </value> <balue> classpath:redis.properties </value> </list> </property> </bean> <! - jedis接続プール - > <bean id = "poolconfig"> <プロパティネーム= "maxidle" value = "$ {redis.maxidle}"/> <プロパティname = "maxtotal" value = "$ {redis.maxactive}"/> <プロパティname = "maxwaitmillis" value = "$ {redis.maxwait}"/> <プロパティname = "testonborrow =" $ {redis.testonborrow} "プールプールは必須オプションではありません:タイムアウト/パスワード - > <bean id = "jedispool"> <constructor-arg index = "0" ref = "poolconfig"/> <constructor-arg index = "1" value = {redis.host} "/>> <constructor-arg index =" 2 "2" "$ {construction}" intor-constati value = "$ {redis.timeout}" type = "int"/> <! - <constructor-arg index = "4" value = "$ {redis.password}"/> </bean> <! - jedis connection Factory-> <bean id = "jedisconnectionfactory"> <propertion nam value = "$ {redis.port}"/> <property name = "hostname" value = "$ {redis.host}"/> <! - <property name = "property name =" password "value =" $ {redis.pass} "/> - > </bean> <util:定数static-field = "org.springframework.session.data.redis.config.configureredisaction.no_op"/> <! - spring redisテンプレート - > <bean id = "redistemplate"> <プロパティ名= "connectionfactory" ref = "jedisconnectionfactory"/> </bean <! id = "RedishtttssessionConfiguration"> <Property name = "MaxinactiveIntervalinseconds" value = "1800"/> </bean> <! - mybatisの統合 - > <bean id = "sqlsessionfactory" value = "classpath:com/zyt/**/**。xml"/> </bean> <bean> <basepackage "value =" com.zyt。*。dao "/> <プロパティ名=" Transaction-Manager = "TransactionManager"/> <bean id = "transactionmanager"> <プロパティ名= "dataSource" ref = "dataSource"/> </bean> <! - データベース設定 - > <bean id = "dataSource" Destroy-method = "close" init-method = "" promic name = "url" orl "$" orl "$" $ "$" orl <プロパティ名= "username" value = "$ {jdbc_username}"/> <property name = "password" value = "$ {jdbc_password}"/> <! - 接続サイズの初期化 - > <プロパティname = "Initialsize" value = "0"/> < Idle "value =" Property name = "minidle" value = "0" /> <! - 最大接続待機時間を取得 - > <プロパティ名= "maxwait" value = "60000" /> <! - <プロパティ名= "poolpreparedStatements" value = "true" /> <property name = " value = "$ {validationQuery}"/> <プロパティ名= "testonborrow" value = "false"/> <property name = "testonborrow" value = "false"/> <プロパティname = "testwhileidle" value = "true"/> <! - 検出されるために検出されるためにどのくらい時間がかかるかを構成します。 name = "timebetheevictionrunsmillis" value = "60000"/> <! - プールで生き残るための最小時間をMillisecondsで構成 - > <プロパティ名= "minevictableidletimemillis" value = "25200000"/> <つまり、30分 - > <プロパティ名= "removeabandonedtimeout" value = "1800"/> <! - 放棄された接続を閉じるときの出力エラーログ - > <プロパティname = "logabanded" value = "true"/> <! - 監視データベース - > <!JDBC.Properties
DriverClassName = com.mysql.jdbc.driver validationquery = Select 1 jdbc_url = jdbc:mysql:// localhost:3306/zyt_demo?useunicode = true&charatereCoding = utf-8&zerodateTimebehavior = converttonull jdbc_uuserame
Redis.Properties
redis.isopen = on redis.host = 127.0.0.1 redis.port = 6379 redis.maxidle = 300 redis.maxactive = 600 redis.maxwait = 1000 redis.testonborrow = true redis.timeout = 2000#redis.password =
上記は統合された構成ファイルで、Redisに関する構成は統合の成功の鍵です
質問の概要
1.スタートアッププロジェクトは、構成ファイルの位置のために統合を統合した後、例外として報告されたため、起動は失敗しました。何度か試してみてください。上記の構成ファイルを使用できます。
2。私は以前にキャッシュツールクラスに電話をかけましたが、ジェダイスプールの注入が空であることを示しました。コントローラーに注入され、値がありました。私がコントローラーのツールクラスを呼び出した方法は新品だったため、ツールクラスをスキャンするとSpringがJedispoolインジェクションを失いました。コントローラーで代わりに注入ツールクラスを使用して解決できます。
例えば:
要約します
上記は、Redis(Jedis)を統合してセッションの共有を実現するプロセスです。すべての人に役立つことを願っています。ご質問がある場合は、メッセージを残してください。編集者は、すべての人に時間内に返信します。 wulin.comのウェブサイトへのご支援ありがとうございます!