Spring整合Redis&JSON序列化&Spring/Web項目部署相關


幾種JSON框架用法和效率對比:

https://blog.csdn.net/sisyphus_z/article/details/53333925

https://blog.csdn.net/weixin_42476601/article/details/81700981

https://blog.csdn.net/xuSir_1/article/details/72461364

https://www.cnblogs.com/cdf-opensource-007/p/6395458.html

https://blog.csdn.net/fanpeng1100/article/details/52856813

https://www.cnblogs.com/songjinduo/p/5279461.html

https://www.cnblogs.com/fly-piglet/p/5406506.html

json-lib:

http://www.cnblogs.com/sharpest/p/7844533.html

https://www.cnblogs.com/teach/p/5791029.html

Jackson:

https://blog.csdn.net/weixin_38111957/article/details/81585392

Gson:

https://www.cnblogs.com/majay/p/6336918.html

https://blog.csdn.net/axuanqq/article/details/51441590

fastJson:

https://blog.csdn.net/fullbug/article/details/78629033

 

Spring整合JUnit4:

https://blog.csdn.net/qq_32786873/article/details/56480880

 

Spring注解加載配置文件:

http://www.cnblogs.com/warehouse/p/8681187.html

https://www.cnblogs.com/lyjing/p/8406827.html

https://blog.csdn.net/haha_sir/article/details/79105951

https://blog.csdn.net/qq_15204179/article/details/82178802

Spring代碼獲取配置文件屬性值:

https://www.cnblogs.com/yzuzhang/p/7399732.html

https://www.cnblogs.com/Gyoung/p/5507063.html

SpringBoot讀取配置文件:

https://blog.csdn.net/qq_32786873/article/details/52840745

Spring的@Configuration配置類引入xml:

https://www.cnblogs.com/ya-qiang/p/9506485.html

 

純注解配置SpringMVC:

https://blog.csdn.net/ykzhen2015/article/details/70666623

https://www.cnblogs.com/yxth/p/6907752.html

傳統配置消息轉換器和自定義消息轉換器:

https://www.cnblogs.com/zfding/p/8322382.html

舊版消息轉換器配置:

https://www.jianshu.com/p/2f633cb817f5

 

Web項目部署問題:

1.Mapper方法找不到對應綁定:源於pom文件中的maven打包沒有配置resource把Mapper.xml打包到classes目錄中,也就是實際運行缺少Mapper.xml文件,

需要在pom.xml中加入(如果Mapper.xml放在resources里面就不需要了):

<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>

問題和解決辦法詳見:

https://blog.csdn.net/oMrLeft123/article/details/70239951

https://www.cnblogs.com/lfm601508022/p/InvalidBoundStatement.html

2.找不到/WEB-INF/views下自定義的jsp頁面,源於使用IDEA的Artifacts打包時,Web模塊的自定義文件夾需要手動加入,具體方法如下:

補充:jsp的c:foreach標簽用法:

https://www.cnblogs.com/cai170221/p/8035925.html

3.maven命令打包報錯找不到webxml配置或web.xml文件

需要在pom.xml中手動指定其位置

<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<!--<version>2.5</version>-->
<webXml>web/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
</plugins>

參考:

https://www.cnblogs.com/sxdcgaq8080/p/5704178.html

不創建web.xml的解決辦法:

https://blog.csdn.net/zwx19921215/article/details/49076443

IDEA中有時部署Tomcat需要重新編譯,在Project Structure中指定Web模塊的根目錄位置,讓其變成小地球標志,然后按2中方式,在Artifacts中加入自定義文件夾,有時需要加入web.xml文件

maven打包時打war包:

<packaging>war</packaging>

使用Lifecycle下的install命令:

或使用build中配置的各種插件(比如compile插件,spring boot插件等)

 

springmvc(Web)整合logback:

https://blog.csdn.net/kity9420/article/details/81042580

https://www.cnblogs.com/xy-nb/p/7544880.html

https://www.cnblogs.com/softidea/archive/2016/03/13/5271761.html

 

mybatis打印sql:

https://www.cnblogs.com/qlong8807/p/5580424.html

https://www.cnblogs.com/jpfss/p/8425381.html

mybatis官方文檔:

http://www.mybatis.org/mybatis-3/zh/configuration.html#settings

 

MyBatis中Mapper.xml文件位置配置和打包引入方式:

https://blog.csdn.net/fanfanzk1314/article/details/71480954/

https://blog.csdn.net/lmy86263/article/details/53428417

https://blog.csdn.net/bestcxx/article/details/72966768

Spring整合MyBatis的Mapper類配置:

https://blog.csdn.net/sinat_25295611/article/details/70832971

http://www.cnblogs.com/wangmingshun/p/5674633.html

 

Maven打包自定義包含資源文件:

http://bglmmz.iteye.com/blog/2063856

https://www.cnblogs.com/panie2015/p/5737393.html

在Web項目使用maven打包時,就使用maven-war-plugin插件,指定web資源根目錄,配置成WEB-INF目錄即可,這樣在IDEA中配置Web模塊時也指定根目錄為WEB-INF,這樣在Artifacts中導出war包和使用maven打war包時就可以包含到WEB-INF目錄下的jsp資源目錄和web.xml文件,具體配置如下:

<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<!--<version>2.5</version>-->
<webResources>
<resource>
<!-- 元配置文件的目錄,相對於pom.xml文件的路徑 -->
<directory>web/WEB-INF</directory>
<!-- 是否過濾文件,也就是是否啟動auto-config的功能 -->
<filtering>true</filtering>
<!-- 目標路徑 -->
<targetPath>WEB-INF</targetPath>
</resource>
</webResources>
<webXml>web/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>

 

Spring整合Redis作為緩存(使用@EnableCaching):

http://www.cnblogs.com/hello-daocaoren/p/7891907.html

https://www.cnblogs.com/sxdcgaq8080/p/7228163.html

http://www.cnblogs.com/java-class/p/7112541.html

https://www.cnblogs.com/qlqwjy/p/8574121.html

手動(代碼)緩存(結合Spring):

http://www.cnblogs.com/qlqwjy/p/8562703.html

Spring緩存注解:

http://www.cnblogs.com/qlqwjy/p/8559119.html

緩存注解操作多個緩存(使用@Caching):

https://blog.csdn.net/whatlookingfor/article/details/51833378/

SpEL表達式:

https://docs.spring.io/spring/docs/4.2.x/spring-framework-reference/html/expressions.html

手寫模糊和批量刪除(aspect,aop):

https://www.cnblogs.com/zer0Black/p/8410984.html

https://blog.csdn.net/fycstart/article/details/82706646

https://blog.csdn.net/yangshangwei/article/details/77961449

緩存注解key異常問題(字符串類型要加單引號!!):

https://www.oschina.net/question/3429421_2254437

<cache:annotation-driven/>啟動緩存注解,和使用Cache接口自定義緩存操作、序列化

https://www.cnblogs.com/Revel-sl/p/5841861.html

 

 

Jackson序列化注解實現POJO的JSON序列化(用於SpringMVC的@ResponseBody返回POJO數據,需要配合Jackson消息轉換器):

https://blog.csdn.net/wslyk606/article/details/78325474

https://blog.csdn.net/u011181882/article/details/81300613

https://www.cnblogs.com/luxianyu-s/p/9640588.html

https://blog.csdn.net/qq_16739081/article/details/81053391

 

Spring整合Redis序列化:

https://blog.csdn.net/xiaolyuh123/article/details/78682200

https://blog.csdn.net/u013958151/article/details/80603365

http://blog.51cto.com/10705830/2166146

Spring整合Redis序列化原理和自定義序列化:

https://www.cnblogs.com/cuglkb/p/6895423.html

https://www.cnblogs.com/liuchao102/p/4479352.html

https://www.cnblogs.com/yaobolove/p/5632891.html

序列化問題:

https://www.2cto.com/kf/201807/764238.html

序列化性能比較和壓力測試:

https://blog.csdn.net/boling_cavalry/article/details/80719683

https://blog.csdn.net/bing2011/article/details/80106193

 

 

緩存key生成問題:

官方gitHub問題解答:

https://github.com/spring-projects/spring-boot/issues/3625

截取:

@Configuration @EnableCaching public class RedisConfig { @Bean public KeyGenerator simpleKeyGenerator() { return (target, method, params) -> { StringBuilder sb = new StringBuilder(); sb.append(target.getClass().getName()); sb.append(method.getName()); for (Object obj : params) { sb.append(obj.toString()); } return sb.toString(); }; } @Bean public CacheManager cacheManager(RedisTemplate redisTemplate) { return new RedisCacheManager(redisTemplate); } @Bean public StringRedisTemplate redisTemplate(RedisConnectionFactory factory) { final StringRedisTemplate template = new StringRedisTemplate(factory); Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class); ObjectMapper om = new ObjectMapper(); om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); jackson2JsonRedisSerializer.setObjectMapper(om); template.setValueSerializer(jackson2JsonRedisSerializer); template.afterPropertiesSet(); return template; } }
@CacheConfig(cacheNames = "bangumis") @Cacheable

I am not sure that your KeyGenerator is taken into account. Could you please extend CachingConfigurerSupport and make sure you override the keyGenerator() method please? (This is actually unrelated to Spring Boot).

More info in the doc

if i set keyGenerator@CacheConfig(cacheNames = "bangumis",keyGenerator = "simpleKeyGenerator")

it work,but for this I must set this keyGenerator in everywhere?

 

I just told you.

@Configuration
@EnableCaching public class RedisConfig extends CachingConfigurerSupport { @Bean @Override public KeyGenerator keyGenerator() { ... } ... }

ok,thank you

https://blog.csdn.net/u012557814/article/details/79933416

https://blog.csdn.net/qq_36470507/article/details/78967640?utm_source=blogxgwz6

@EnableCaching注解:

https://blog.csdn.net/zl_momomo/article/details/80403564

spring-data-redis緩存序列化:

https://blog.csdn.net/y666666y/article/details/70212767

spring-data-redis緩存注解:

https://blog.csdn.net/sanjay_f/article/details/47372967

 

 

高可用Redis配置:

https://www.cnblogs.com/tankaixiong/p/3660075.html

http://www.cnblogs.com/cunkouzh/p/9242292.html

https://www.cnblogs.com/shihaiming/p/6050777.html 

 

 

Spring Boot整合Redis:

 

 

Redis安裝問題:

1.Ubuntu默認無法使用root用戶(沒有密碼),普通用戶執行make等需要sudo

2.cp,tar,wget這些命令在/usr/local這樣的目錄使用普通用戶執行,沒有權限,一般是因為無法在這些目錄創建新的文件或目錄,因為普通用戶沒有這些目錄的寫權限(w),所以也要用sudo

3.普通用戶啟動Redis等軟件應用,是否能成功,要看其是否有相關命令文件的可執行權限(x),配置文件的讀權限(r),而不是安裝在了什么目錄,當然一般需要能進入這些目錄

4.Redis啟動后無法通過redis-cli或強制ctrl+c終止,提示無法向DB保存數據,是因為啟動用戶沒有配置文件redis.conf中配置的DB目錄寫權限。需要修改配置dir為啟動用戶有寫權限的目錄,比如啟動用戶根目錄,具體子目錄需要先創建,否則啟動時提示找不到!問題具體參考:

https://www.bbsmax.com/A/ke5jVjMa5r/

5.make,make install和./configure的作用:

https://www.cnblogs.com/tinywan/p/7230039.html

https://www.cnblogs.com/dsc65749924/p/5852177.html

6.自定義安裝目錄:(注意PREFIX大寫,有等號)

注意默認情況的make install可以將redis命令拷貝到/usr/local/bin目錄,這是$PATH默認包含的目錄,這樣在任何目錄可執行

如果自定義安裝目錄,則不會在$PATH中,需要手動添加

注意需要拷貝配置文件到自定義安裝目錄的某處,以便自定義啟動

redis.conf是redis的配置文件,安裝的時候不會在安裝目錄自動生成,所以要手動從redis的解壓目錄里拷貝過去(還是在解壓目錄中操作):

 cp redis.conf /usr/local/redis/bin

注意配置文件中需要配置pid filelog filedir 等,且需要事先創建對應目錄普通啟動用戶需要對這些目錄有可執行、寫文件權限,對應文件有讀寫權限,詳見第7步配置詳解中需要注意的。

注意:默認只以./redis-server &啟動並不會加載任何目錄的配置文件,而是默認啟動!試過將配置文件配置好放在同一目錄以普通用戶啟動,但仍然出現通過redis-cli來shutdown的db文件無法保存問題:

127.0.0.1:6379> shutdown
9389:M 04 Dec 09:47:54.106 # User requested shutdown...
9389:M 04 Dec 09:47:54.106 * Saving the final RDB snapshot before exiting.
9389:M 04 Dec 09:47:54.106 # Failed opening the RDB file dump.rdb (in server root dir /usr/local/redis/bin) for saving: Permission denied
9389:M 04 Dec 09:47:54.107 # Error trying to save the DB, can't exit.
(error) ERR Errors trying to SHUTDOWN. Check logs.

說明默認沒使用任何配置文件!

如果以./redis-server ./redis.conf &啟動則順利加載配置文件,各種文件寫入了配置文件中配置的目錄,文件名OK.

所以生產環境控制一定要像上面這樣這樣指定配置好的配置文件啟動!!

https://blog.csdn.net/huyuyang6688/article/details/51859899

https://www.jianshu.com/p/3646c46940c3

https://www.cnblogs.com/_popc/p/3684835.html

配置與開機啟動(服務):

https://www.cnblogs.com/moxiaoan/p/5724505.html

https://www.cnblogs.com/it-cen/p/4295984.html

https://www.cnblogs.com/Mike_Chang/p/9582185.html

7.配置詳解:

參照:(redis.conf文件注釋的完整翻譯)

http://www.cnblogs.com/zhang-ke/p/5981108.html

http://www.cnblogs.com/kreo/p/4423362.html

https://www.cnblogs.com/pqchao/p/6558688.html

https://www.cnblogs.com/zxtceq/p/7676911.html

https://www.cnblogs.com/happyday56/p/3916388.html

注意:

pid 進程pid文件存儲文件,需要啟動用戶有讀寫權限,上級目錄需要先存在

filelog 日志存儲文件需要啟動用戶有讀寫權限,上級目錄需要先存在

filedir 數據存儲目錄,必須是目錄!需要啟動用戶有讀寫權限(可以在其中創建文件),上級目錄需要先存在

 

這里這幾個配置的上級目錄均設置到了啟動用戶家目錄下的一個目錄

 

Redis集群解決方案:

介紹:

https://www.zhihu.com/question/21419897

https://blog.csdn.net/u011277123/article/details/55002024

https://blog.csdn.net/sanpo/article/details/52839044

三種集群模式:

https://blog.csdn.net/c295477887/article/details/52487621

https://blog.csdn.net/u012129558/article/details/77146287

https://blog.csdn.net/keketrtr/article/details/78802571

https://blog.csdn.net/q649381130/article/details/79931791

哨兵模式詳解:

https://blog.csdn.net/lee_nacl/article/details/64125831

https://blog.csdn.net/tengxing007/article/details/77462578

https://blog.csdn.net/shouhuzhezhishen/article/details/69221517

https://blog.csdn.net/csolo/article/details/53147166

https://blog.csdn.net/guduyishuai/article/details/72823535

哨兵模式注意:(親測

1.將主從數據庫的redis.conf文件,和哨兵的sentinel.conf文件,使用sudo chmod a+w設置為普通用戶可寫,這樣以普通用戶啟動時,主機宕機,哨兵發起選主時,才能修改里面的主從信息!

2.哨兵的sentinel monitor master01 127.0.0.1 6379 2配置,最后的參數2代表選舉時需要的最少(哨兵)投票數。如果多台哨兵宕機,剩下的哨兵少於這個數值,發現哨兵可以偵測到數據庫主機下線,但無法完成選舉剩下的數據庫全部是slave.原主機上線后,仍然是主,哨兵也可偵測到。也就是可用哨兵數少於最少投票數時,無法選舉,主機下線后再無主機,需要其再次上線后才有主機。實際生產環境需要考慮和避免這種多哨兵宕機造成可用哨兵少於投票數的情況的發生!!

 

分片+哨兵:

https://blog.csdn.net/java20150326/article/details/71036347

Redis Cluster架設:

https://www.cnblogs.com/mafly/p/redis_cluster.html

https://blog.csdn.net/huwh_/article/details/79242625

https://www.cnblogs.com/gomysql/p/4395504.html

https://www.cnblogs.com/boshen-hzb/p/7699783.html

https://blog.csdn.net/pincharensheng/article/details/78391305

https://www.cnblogs.com/yuanermen/p/5717885.html

https://www.cnblogs.com/wuxl360/p/5920330.html

https://www.cnblogs.com/PatrickLiu/p/8444546.html

 

緩存設計和雪崩、穿透、更新等解決方案:

https://blog.csdn.net/na_tion/article/details/38614333

https://blog.csdn.net/simba_1986/article/details/77823309

https://blog.csdn.net/u011832039/article/details/78924418

https://blog.csdn.net/u013970991/article/details/70000202

https://blog.csdn.net/xlgen157387/article/details/79530877

http://blog.didispace.com/chengchao-huancun-zuijiazhaoshi/

https://blog.csdn.net/zeb_perfect/article/details/54135506

 

高並發秒殺設計:

https://blog.csdn.net/zgx6208/article/details/53308225

https://blog.csdn.net/CSDN_Terence/article/details/77744042

 

高可用負載均衡策略:
https://blog.csdn.net/hxehuang/article/details/52576293

KeepAlived+Nginx:

https://blog.csdn.net/l1028386804/article/details/72801492

https://blog.csdn.net/xyang81/article/details/52556886

https://blog.csdn.net/e421083458/article/details/30092795

https://blog.csdn.net/yelllowcong/article/details/78764780

https://blog.csdn.net/lijian12388806/article/details/51882333

https://blog.csdn.net/l192168134/article/details/51801483 

Nginx集群:

https://blog.csdn.net/e421083458/article/details/30086413

Nginx+Tomcat:

https://blog.csdn.net/zht666/article/details/38515147

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM