{"id":52343,"date":"2025-08-11T13:34:17","date_gmt":"2025-08-11T05:34:17","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/52343.html"},"modified":"2025-08-11T13:34:17","modified_gmt":"2025-08-11T05:34:17","slug":"spring-boot-%e9%ab%98%e7%ba%a7%e7%bc%93%e5%ad%98%e7%ad%96%e7%95%a5%ef%bc%9a%e6%89%93%e9%80%a0%e9%ab%98%e6%80%a7%e8%83%bd%e5%ba%94%e7%94%a8%e7%9a%84%e7%a7%98%e5%af%86%e6%ad%a6%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/52343.html","title":{"rendered":"Spring Boot \u9ad8\u7ea7\u7f13\u5b58\u7b56\u7565\uff1a\u6253\u9020\u9ad8\u6027\u80fd\u5e94\u7528\u7684\u79d8\u5bc6\u6b66\u5668"},"content":{"rendered":"<p>\u5f15\u8a00\u00a0<\/p>\n<p>\u5728\u9ad8\u5e76\u53d1\u5e94\u7528\u4e2d&#xff0c;\u7f13\u5b58\u662f\u63d0\u5347\u6027\u80fd\u7684\u5173\u952e\u624b\u6bb5\u3002Spring Boot\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u7f13\u5b58\u62bd\u8c61\u548c\u96c6\u6210\u652f\u6301&#xff0c;\u4f46\u5982\u4f55\u5408\u7406\u4f7f\u7528\u7f13\u5b58\u3001\u907f\u514d\u5e38\u89c1\u9677\u9631&#xff0c;\u9700\u8981\u6df1\u5165\u7406\u89e3\u7f13\u5b58\u7684\u5de5\u4f5c\u539f\u7406\u548c\u6700\u4f73\u5b9e\u8df5\u3002\u672c\u6587\u5c06\u5206\u4eabSpring Boot\u4e2d\u7684\u9ad8\u7ea7\u7f13\u5b58\u7b56\u7565&#xff0c;\u5e2e\u52a9\u4f60\u6784\u5efa\u9ad8\u6548\u3001\u53ef\u9760\u7684\u7f13\u5b58\u7cfb\u7edf\u3002<\/p>\n<p>&#x1f50d; Spring Boot \u7f13\u5b58\u57fa\u7840<\/p>\n<h4>&#x1f527; 1. \u542f\u7528\u7f13\u5b58\u652f\u6301<\/h4>\n<p>&#064;SpringBootApplication&#064;EnableCachingpublic\u00a0class\u00a0CacheApplication\u00a0{\u00a0 \u00a0\u00a0public\u00a0static\u00a0void\u00a0main(String[] args) {\u00a0 \u00a0 \u00a0 \u00a0\u00a0SpringApplication.run(CacheApplication.class, args);\u00a0 \u00a0 }}<\/p>\n<h4>&#x1f4cc; 2. \u6838\u5fc3\u7f13\u5b58\u6ce8\u89e3<\/h4>\n<ul>\n<li>&#064;Cacheable&#xff1a;\u6807\u8bb0\u65b9\u6cd5\u7ed3\u679c\u53ef\u7f13\u5b58\u00a0<\/li>\n<li>&#064;CacheEvict&#xff1a;\u6e05\u9664\u7f13\u5b58<\/li>\n<li>&#064;CachePut&#xff1a;\u66f4\u65b0\u7f13\u5b58\u800c\u4e0d\u5f71\u54cd\u65b9\u6cd5\u6267\u884c<\/li>\n<li>&#064;Caching&#xff1a;\u7ec4\u5408\u591a\u4e2a\u7f13\u5b58\u64cd\u4f5c<\/li>\n<li>&#064;CacheConfig&#xff1a;\u7c7b\u7ea7\u522b\u7f13\u5b58\u914d\u7f6e<\/li>\n<\/ul>\n<h4>&#x1f4bb; 3. \u7b80\u5355\u7f13\u5b58\u914d\u7f6e\u793a\u4f8b<\/h4>\n<p>&#064;Service&#064;CacheConfig(cacheNames &#061;\u00a0&#034;users&#034;)public\u00a0class\u00a0UserService\u00a0{\u00a0 \u00a0\u00a0&#064;Autowired\u00a0 \u00a0\u00a0private\u00a0UserRepository userRepository;\u00a0 \u00a0\u00a0&#064;Cacheable(key &#061;\u00a0&#034;#id&#034;)\u00a0 \u00a0\u00a0public\u00a0User getUserById(Long\u00a0id) {\u00a0 \u00a0 \u00a0 \u00a0\u00a0\/\/ \u6a21\u62df\u6162\u67e5\u8be2\u00a0 \u00a0 \u00a0 \u00a0\u00a0try\u00a0{ Thread.sleep(2000); }\u00a0catch\u00a0(InterruptedException e) {}\u00a0 \u00a0 \u00a0 \u00a0\u00a0return\u00a0userRepository.findById(id).orElse(null);\u00a0 \u00a0 }\u00a0 \u00a0\u00a0&#064;CacheEvict(key &#061;\u00a0&#034;#id&#034;)\u00a0 \u00a0\u00a0public\u00a0void deleteUser(Long\u00a0id) {\u00a0 \u00a0 \u00a0 \u00a0 userRepository.deleteById(id);\u00a0 \u00a0 }\u00a0 \u00a0\u00a0&#064;CachePut(key &#061;\u00a0&#034;#user.id&#034;)\u00a0 \u00a0\u00a0public\u00a0User updateUser(User user) {\u00a0 \u00a0 \u00a0 \u00a0\u00a0return\u00a0userRepository.save(user);\u00a0 \u00a0 }}<\/p>\n<p>\u26a1 \u9ad8\u7ea7\u7f13\u5b58\u7b56\u7565<\/p>\n<h4>&#x1f504; 1. \u591a\u7ea7\u7f13\u5b58\u5b9e\u73b0<\/h4>\n<p>\u7ed3\u5408\u672c\u5730\u7f13\u5b58\u548c\u5206\u5e03\u5f0f\u7f13\u5b58&#xff0c;\u517c\u987e\u6027\u80fd\u548c\u4e00\u81f4\u6027\u3002<\/p>\n<h5>&#x1f4e6; \u6dfb\u52a0\u4f9d\u8d56<\/h5>\n<p>&lt;dependency&gt;\u00a0 \u00a0\u00a0&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\u00a0 \u00a0\u00a0&lt;artifactId&gt;spring-boot-starter-cache&lt;\/artifactId&gt;&lt;\/dependency&gt;&lt;dependency&gt;\u00a0 \u00a0\u00a0&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\u00a0 \u00a0\u00a0&lt;artifactId&gt;spring-boot-starter-data-redis&lt;\/artifactId&gt;&lt;\/dependency&gt;<\/p>\n<h5>\u2699\ufe0f \u591a\u7ea7\u7f13\u5b58\u914d\u7f6e<\/h5>\n<p>&#064;Configurationpublic\u00a0class\u00a0MultiLevelCacheConfig\u00a0{\u00a0 \u00a0\u00a0\/\/ \u672c\u5730\u7f13\u5b58\u914d\u7f6e\u00a0 \u00a0\u00a0&#064;Bean\u00a0 \u00a0\u00a0public\u00a0CaffeineCacheManager\u00a0caffeineCacheManager() {\u00a0 \u00a0 \u00a0 \u00a0\u00a0CaffeineCacheManager\u00a0cacheManager &#061;\u00a0new\u00a0CaffeineCacheManager();\u00a0 \u00a0 \u00a0 \u00a0 cacheManager.setCaffeine(Caffeine.newBuilder()\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .expireAfterWrite(10,\u00a0TimeUnit.MINUTES)\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .maximumSize(1000));\u00a0 \u00a0 \u00a0 \u00a0\u00a0return\u00a0cacheManager;\u00a0 \u00a0 }\u00a0 \u00a0\u00a0\/\/ Redis\u7f13\u5b58\u914d\u7f6e\u00a0 \u00a0\u00a0&#064;Bean\u00a0 \u00a0\u00a0public\u00a0RedisCacheManager\u00a0redisCacheManager(RedisConnectionFactory connectionFactory) {\u00a0 \u00a0 \u00a0 \u00a0\u00a0RedisCacheConfiguration\u00a0config &#061;\u00a0RedisCacheConfiguration.defaultCacheConfig()\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .entryTtl(Duration.ofMinutes(30))\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .disableCachingNullValues();\u00a0 \u00a0 \u00a0 \u00a0\u00a0return\u00a0RedisCacheManager.builder(connectionFactory)\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .cacheDefaults(config)\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .withCacheConfiguration(&#034;users&#034;,\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofHours(1)))\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .build();\u00a0 \u00a0 }\u00a0 \u00a0\u00a0\/\/ \u591a\u7ea7\u7f13\u5b58\u7ba1\u7406\u5668\u00a0 \u00a0\u00a0&#064;Bean\u00a0 \u00a0\u00a0public\u00a0CacheManager\u00a0multiLevelCacheManager(CaffeineCacheManager caffeineCacheManager,\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0RedisCacheManager redisCacheManager) {\u00a0 \u00a0 \u00a0 \u00a0\u00a0CompositeCacheManager\u00a0cacheManager &#061;\u00a0new\u00a0CompositeCacheManager(caffeineCacheManager, redisCacheManager);\u00a0 \u00a0 \u00a0 \u00a0 cacheManager.setFallbackToNoOpCache(false);\u00a0 \u00a0 \u00a0 \u00a0\u00a0return\u00a0cacheManager;\u00a0 \u00a0 }}<\/p>\n<h5><\/h5>\n<h4>&#x1f6e1;\ufe0f 2. \u7f13\u5b58\u7a7f\u900f\u9632\u62a4<\/h4>\n<p>\u7f13\u5b58\u7a7f\u900f\u662f\u6307\u67e5\u8be2\u4e0d\u5b58\u5728\u7684\u6570\u636e&#xff0c;\u5bfc\u81f4\u8bf7\u6c42\u76f4\u63a5\u843d\u5230\u6570\u636e\u5e93\u4e0a\u3002<\/p>\n<h5>&#x1f4a1; \u89e3\u51b3\u65b9\u68481&#xff1a;\u7f13\u5b58\u7a7a\u503c<\/h5>\n<p>&#064;Cacheable(key &#061;\u00a0&#034;#id&#034;, cacheNames &#061;\u00a0&#034;users&#034;, unless &#061;\u00a0&#034;#result &#061;&#061; null&#034;)public\u00a0User getUserById(Long\u00a0id) {\u00a0 \u00a0\u00a0return\u00a0userRepository.findById(id).orElse(null);}\/\/ \u6539\u8fdb\u7248&#xff1a;\u7f13\u5b58\u7a7a\u503c&#064;Cacheable(key &#061;\u00a0&#034;#id&#034;, cacheNames &#061;\u00a0&#034;users&#034;)public\u00a0User getUserByIdWithNullCache(Long\u00a0id) {\u00a0 \u00a0 User user &#061; userRepository.findById(id).orElse(null);\u00a0 \u00a0\u00a0\/\/ \u7f13\u5b58\u7a7a\u503c&#xff0c;\u907f\u514d\u7f13\u5b58\u7a7f\u900f\u00a0 \u00a0\u00a0return\u00a0user !&#061;\u00a0null\u00a0? user : new User();\u00a0\/\/ \u8fd4\u56de\u7a7a\u5bf9\u8c61\u800c\u4e0d\u662fnull}<\/p>\n<h5>&#x1f50d; \u89e3\u51b3\u65b9\u68482&#xff1a;\u5e03\u9686\u8fc7\u6ee4\u5668<\/h5>\n<p>&#064;Configurationpublic\u00a0class\u00a0BloomFilterConfig\u00a0{\u00a0 \u00a0\u00a0&#064;Bean\u00a0 \u00a0\u00a0public\u00a0BloomFilter&lt;Long&gt; userIdBloomFilter() {\u00a0 \u00a0 \u00a0 \u00a0\u00a0\/\/ \u9884\u8ba1\u5143\u7d20\u6570\u91cf\u3001\u8bef\u5224\u7387\u00a0 \u00a0 \u00a0 \u00a0 BloomFilter&lt;Long&gt; filter &#061; BloomFilter.create(Funnels.longFunnel(),\u00a0100000,\u00a00.01);\u00a0 \u00a0 \u00a0 \u00a0\u00a0\/\/ \u9884\u70ed\u5e03\u9686\u8fc7\u6ee4\u5668\u00a0 \u00a0 \u00a0 \u00a0 List&lt;Long&gt; userIds &#061; userRepository.findAllIds();\u00a0 \u00a0 \u00a0 \u00a0 userIds.forEach(filter::put);\u00a0 \u00a0 \u00a0 \u00a0\u00a0return\u00a0filter;\u00a0 \u00a0 }}&#064;Servicepublic\u00a0class\u00a0UserService\u00a0{\u00a0 \u00a0\u00a0&#064;Autowired\u00a0 \u00a0\u00a0private\u00a0BloomFilter&lt;Long&gt; userIdBloomFilter;\u00a0 \u00a0\u00a0&#064;Cacheable(key &#061;\u00a0&#034;#id&#034;)\u00a0 \u00a0\u00a0public\u00a0User getUserByIdWithBloomFilter(Long\u00a0id) {\u00a0 \u00a0 \u00a0 \u00a0\u00a0\/\/ \u5148\u68c0\u67e5\u5e03\u9686\u8fc7\u6ee4\u5668\u00a0 \u00a0 \u00a0 \u00a0\u00a0if\u00a0(!userIdBloomFilter.mightContain(id)) {\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0return\u00a0null;\u00a0\/\/ \u5feb\u901f\u8fd4\u56de&#xff0c;\u907f\u514d\u6570\u636e\u5e93\u67e5\u8be2\u00a0 \u00a0 \u00a0 \u00a0 }\u00a0 \u00a0 \u00a0 \u00a0\u00a0return\u00a0userRepository.findById(id).orElse(null);\u00a0 \u00a0 }}<\/p>\n<h5><\/h5>\n<h4>&#x1f525; 3. \u7f13\u5b58\u9884\u70ed<\/h4>\n<p>\u5728\u5e94\u7528\u542f\u52a8\u65f6\u9884\u5148\u52a0\u8f7d\u70ed\u70b9\u6570\u636e\u5230\u7f13\u5b58\u3002<\/p>\n<p>&#064;Component&#064;Slf4jpublic\u00a0class\u00a0CacheWarmer\u00a0implements\u00a0CommandLineRunner\u00a0{\u00a0 \u00a0\u00a0&#064;Autowired\u00a0 \u00a0\u00a0private\u00a0UserService\u00a0userService;\u00a0 \u00a0\u00a0&#064;Autowired\u00a0 \u00a0\u00a0private\u00a0CacheManager\u00a0cacheManager;\u00a0 \u00a0\u00a0&#064;Override\u00a0 \u00a0\u00a0public\u00a0void\u00a0run(String&#8230; args) {\u00a0 \u00a0 \u00a0 \u00a0 log.info(&#034;\u5f00\u59cb\u7f13\u5b58\u9884\u70ed&#8230;&#034;);\u00a0 \u00a0 \u00a0 \u00a0\u00a0\/\/ \u52a0\u8f7d\u70ed\u70b9\u7528\u6237\u6570\u636e\u00a0 \u00a0 \u00a0 \u00a0\u00a0List&lt;Long&gt; hotUserIds &#061;\u00a0Arrays.asList(1L, 2L, 3L, 4L, 5L);\u00a0 \u00a0 \u00a0 \u00a0 hotUserIds.forEach(userId -&gt; {\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 userService.getUserById(userId);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 log.info(&#034;\u9884\u70ed\u7528\u6237\u6570\u636e: {}&#034;, userId);\u00a0 \u00a0 \u00a0 \u00a0 });\u00a0 \u00a0 \u00a0 \u00a0 log.info(&#034;\u7f13\u5b58\u9884\u70ed\u5b8c\u6210&#034;);\u00a0 \u00a0 }}<\/p>\n<h4>\u23f1\ufe0f 4. \u7f13\u5b58\u8fc7\u671f\u4e0e\u5237\u65b0\u7b56\u7565<\/h4>\n<h5>&#x1f504; \u5b9a\u65f6\u5237\u65b0\u7f13\u5b58<\/h5>\n<p>&#064;Scheduled(fixedRate &#061; 3600000)\u00a0\/\/ \u6bcf\u5c0f\u65f6\u6267\u884c\u4e00\u6b21public\u00a0void\u00a0refreshHotUserData()\u00a0{\u00a0 \u00a0 log.info(&#034;\u5f00\u59cb\u5237\u65b0\u70ed\u70b9\u7528\u6237\u6570\u636e&#8230;&#034;);\u00a0 \u00a0 List&lt;Long&gt; hotUserIds &#061; userRepository.findHotUserIds();\u00a0 \u00a0 hotUserIds.forEach(userId -&gt; {\u00a0 \u00a0 \u00a0 \u00a0\u00a0\/\/ \u4e3b\u52a8\u5237\u65b0\u7f13\u5b58\u00a0 \u00a0 \u00a0 \u00a0\u00a0User\u00a0user\u00a0&#061;\u00a0userRepository.findById(userId).orElse(null);\u00a0 \u00a0 \u00a0 \u00a0\u00a0if\u00a0(user !&#061;\u00a0null) {\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 cacheManager.getCache(&#034;users&#034;).put(userId, user);\u00a0 \u00a0 \u00a0 \u00a0 }\u00a0 \u00a0 });\u00a0 \u00a0 log.info(&#034;\u70ed\u70b9\u7528\u6237\u6570\u636e\u5237\u65b0\u5b8c\u6210&#034;);}<\/p>\n<h5><\/h5>\n<h5>&#x1f552; \u6ed1\u52a8\u7a97\u53e3\u8fc7\u671f\u7b56\u7565<\/h5>\n<p>&#064;Beanpublic\u00a0CaffeineCacheManager\u00a0caffeineCacheManager() {\u00a0 \u00a0\u00a0CaffeineCacheManager\u00a0cacheManager &#061;\u00a0new\u00a0CaffeineCacheManager();\u00a0 \u00a0 cacheManager.setCaffeine(Caffeine.newBuilder()\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .expireAfterAccess(10,\u00a0TimeUnit.MINUTES)\u00a0\/\/ \u6700\u540e\u4e00\u6b21\u8bbf\u95ee\u540e\u8fc7\u671f\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .maximumSize(1000));\u00a0 \u00a0\u00a0return\u00a0cacheManager;}<\/p>\n<h5><\/h5>\n<p>&#x1f6d2; \u5b9e\u6218\u6848\u4f8b&#xff1a;\u7535\u5546\u5546\u54c1\u8be6\u60c5\u9875\u7f13\u5b58<\/p>\n<h4>&#x1f4cb; 1. \u573a\u666f\u63cf\u8ff0<\/h4>\n<p>\u7535\u5546\u5546\u54c1\u8be6\u60c5\u9875\u9700\u8981\u9891\u7e41\u8bbf\u95ee&#xff0c;\u4e14\u6570\u636e\u66f4\u65b0\u4e0d\u9891\u7e41&#xff0c;\u9002\u5408\u4f7f\u7528\u7f13\u5b58\u4f18\u5316\u3002<\/p>\n<h4>&#x1f4bb; 2. \u5b9e\u73b0\u65b9\u6848<\/h4>\n<p>&#064;Service&#064;CacheConfig(cacheNames &#061;\u00a0&#034;products&#034;)public\u00a0class\u00a0ProductService\u00a0{\u00a0 \u00a0\u00a0&#064;Autowired\u00a0 \u00a0\u00a0private\u00a0ProductRepository productRepository;\u00a0 \u00a0\u00a0&#064;Autowired\u00a0 \u00a0\u00a0private\u00a0RedisTemplate&lt;String, Object&gt; redisTemplate;\u00a0 \u00a0\u00a0\/\/ \u5546\u54c1\u8be6\u60c5\u9875\u7f13\u5b58&#xff0c;\u8bbe\u7f6e1\u5c0f\u65f6\u8fc7\u671f\u00a0 \u00a0\u00a0&#064;Cacheable(key &#061;\u00a0&#034;#id&#034;, cacheNames &#061;\u00a0&#034;productDetails&#034;)\u00a0 \u00a0\u00a0public\u00a0ProductDetailDTO getProductDetail(Long\u00a0id) {\u00a0 \u00a0 \u00a0 \u00a0\u00a0\/\/ \u6a21\u62df\u590d\u6742\u67e5\u8be2\u00a0 \u00a0 \u00a0 \u00a0 Product product &#061; productRepository.findById(id).orElse(null);\u00a0 \u00a0 \u00a0 \u00a0\u00a0if\u00a0(product &#061;&#061;\u00a0null) {\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0return\u00a0null;\u00a0 \u00a0 \u00a0 \u00a0 }\u00a0 \u00a0 \u00a0 \u00a0\u00a0\/\/ \u83b7\u53d6\u5546\u54c1\u56fe\u7247\u3001\u5c5e\u6027\u3001\u8bc4\u4ef7\u7b49\u4fe1\u606f\u00a0 \u00a0 \u00a0 \u00a0 List&lt;String&gt; images &#061; productRepository.findProductImages(id);\u00a0 \u00a0 \u00a0 \u00a0 List&lt;ProductAttribute&gt; attributes &#061; productRepository.findProductAttributes(id);\u00a0 \u00a0 \u00a0 \u00a0\u00a0Double\u00a0avgRating &#061; productRepository.calculateAverageRating(id);\u00a0 \u00a0 \u00a0 \u00a0\u00a0\/\/ \u7ec4\u88c5DTO\u00a0 \u00a0 \u00a0 \u00a0 ProductDetailDTO dto &#061; new ProductDetailDTO();\u00a0 \u00a0 \u00a0 \u00a0 dto.setProduct(product);\u00a0 \u00a0 \u00a0 \u00a0 dto.setImages(images);\u00a0 \u00a0 \u00a0 \u00a0 dto.setAttributes(attributes);\u00a0 \u00a0 \u00a0 \u00a0 dto.setAvgRating(avgRating);\u00a0 \u00a0 \u00a0 \u00a0\u00a0return\u00a0dto;\u00a0 \u00a0 }\u00a0 \u00a0\u00a0\/\/ \u5546\u54c1\u5e93\u5b58\u7f13\u5b58&#xff0c;\u8bbe\u7f6e5\u5206\u949f\u8fc7\u671f\u00a0 \u00a0\u00a0&#064;Cacheable(key &#061;\u00a0&#034;#id&#034;, cacheNames &#061;\u00a0&#034;productStock&#034;)\u00a0 \u00a0\u00a0public\u00a0Integer getProductStock(Long\u00a0id) {\u00a0 \u00a0 \u00a0 \u00a0\u00a0return\u00a0productRepository.getStockById(id);\u00a0 \u00a0 }\u00a0 \u00a0\u00a0\/\/ \u66f4\u65b0\u5546\u54c1\u5e93\u5b58\u65f6\u6e05\u9664\u7f13\u5b58\u00a0 \u00a0\u00a0&#064;CacheEvict(key &#061;\u00a0&#034;#id&#034;, cacheNames &#061;\u00a0&#034;productStock&#034;)\u00a0 \u00a0\u00a0public\u00a0void updateProductStock(Long\u00a0id, Integer stock) {\u00a0 \u00a0 \u00a0 \u00a0 productRepository.updateStock(id, stock);\u00a0 \u00a0 }\u00a0 \u00a0\u00a0\/\/ \u5b9a\u65f6\u5237\u65b0\u5546\u54c1\u5e93\u5b58\u7f13\u5b58\u00a0 \u00a0\u00a0&#064;Scheduled(fixedRate &#061; 300000)\u00a0\/\/ \u6bcf5\u5206\u949f\u6267\u884c\u4e00\u6b21\u00a0 \u00a0\u00a0public\u00a0void refreshProductStockCache() {\u00a0 \u00a0 \u00a0 \u00a0 List&lt;Long&gt; hotProductIds &#061; productRepository.findHotProductIds();\u00a0 \u00a0 \u00a0 \u00a0 hotProductIds.forEach(id -&gt; {\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Integer stock &#061; productRepository.getStockById(id);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 redisTemplate.opsForValue().set(&#034;productStock::&#034;\u00a0&#043; id, stock,\u00a05, TimeUnit.MINUTES);\u00a0 \u00a0 \u00a0 \u00a0 });\u00a0 \u00a0 }}<\/p>\n<h4>&#x1f511; 3.\u5b9e\u73b0\u65b9\u6848\u7f13\u5b58\u952e\u8bbe\u8ba1<\/h4>\n<p>&#064;Configurationpublic\u00a0class\u00a0CacheKeyGeneratorConfig\u00a0{\u00a0 \u00a0\u00a0&#064;Bean\u00a0 \u00a0\u00a0public\u00a0KeyGenerator\u00a0productKeyGenerator() {\u00a0 \u00a0 \u00a0 \u00a0\u00a0return\u00a0(target, method, params) -&gt; {\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0StringBuilder\u00a0sb &#061;\u00a0new\u00a0StringBuilder();\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 sb.append(target.getClass().getName()).append(&#034;:&#034;);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 sb.append(method.getName()).append(&#034;:&#034;);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0for\u00a0(Object\u00a0param : params) {\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 sb.append(param.toString()).append(&#034;:&#034;);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\/\/ \u6dfb\u52a0\u7248\u672c\u53f7&#xff0c;\u4fbf\u4e8e\u7f13\u5b58\u6574\u4f53\u5931\u6548\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 sb.append(&#034;v1&#034;);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0return\u00a0sb.toString();\u00a0 \u00a0 \u00a0 \u00a0 };\u00a0 \u00a0 }}<\/p>\n<h4><\/h4>\n<p>&#x1f4dd; \u6700\u4f73\u5b9e\u8df5\u4e0e\u6ce8\u610f\u4e8b\u9879<\/p>\n<li>\n<p>\u7f13\u5b58\u952e\u8bbe\u8ba1&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5305\u542b\u8db3\u591f\u7684\u4fe1\u606f\u4ee5\u552f\u4e00\u6807\u8bc6\u7f13\u5b58\u9879<\/p>\n<\/li>\n<li>\n<p>\u907f\u514d\u4f7f\u7528\u590d\u6742\u5bf9\u8c61\u4f5c\u4e3a\u952e&#xff0c;\u63a8\u8350\u4f7f\u7528\u7b80\u5355\u7c7b\u578b<\/p>\n<\/li>\n<li>\n<p>\u8003\u8651\u6dfb\u52a0\u7248\u672c\u53f7&#xff0c;\u4fbf\u4e8e\u7f13\u5b58\u6574\u4f53\u5931\u6548<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u7f13\u5b58\u7c92\u5ea6&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u907f\u514d\u7f13\u5b58\u8fc7\u5927\u7684\u5bf9\u8c61&#xff0c;\u62c6\u5206\u4e3a\u66f4\u5c0f\u7684\u7c92\u5ea6<\/p>\n<\/li>\n<li>\n<p>\u6839\u636e\u8bbf\u95ee\u9891\u7387\u548c\u66f4\u65b0\u9891\u7387\u8c03\u6574\u7f13\u5b58\u7b56\u7565<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u7f13\u5b58\u4e00\u81f4\u6027&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u786e\u4fdd\u6570\u636e\u66f4\u65b0\u65f6\u7f13\u5b58\u4e5f\u968f\u4e4b\u66f4\u65b0\u6216\u6e05\u9664<\/p>\n<\/li>\n<li>\n<p>\u5bf9\u4e8e\u5f3a\u4e00\u81f4\u6027\u8981\u6c42&#xff0c;\u8003\u8651\u4f7f\u7528\u5206\u5e03\u5f0f\u9501\u6216\u4e8b\u52a1<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u7f13\u5b58\u76d1\u63a7&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u76d1\u63a7\u7f13\u5b58\u547d\u4e2d\u7387\u3001\u7f13\u5b58\u5927\u5c0f\u7b49\u6307\u6807<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528Spring Boot Actuator\u66b4\u9732\u7f13\u5b58\u6307\u6807<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<p>management:\u00a0 endpoints:\u00a0 \u00a0 web:\u00a0 \u00a0 \u00a0 exposure:\u00a0 \u00a0 \u00a0 \u00a0\u00a0include: cache,health,info<\/p>\n<li>\u5f02\u5e38\u5904\u7406\n<ul>\n<li>\n<p>\u907f\u514d\u7f13\u5b58\u5f02\u5e38\u5f71\u54cd\u4e3b\u4e1a\u52a1\u6d41\u7a0b<\/p>\n<\/li>\n<li>\n<p>\u5b9e\u73b0\u7f13\u5b58\u56de\u9000\u673a\u5236<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<p>&#064;Cacheable(key &#061;\u00a0&#034;#id&#034;, unless &#061;\u00a0&#034;#result &#061;&#061; null&#034;, errorHandler &#061;\u00a0&#034;cacheErrorHandler&#034;)public\u00a0User\u00a0getUserById(Long id) {\u00a0 \u00a0\u00a0\/\/ \u4e1a\u52a1\u903b\u8f91}&#064;Beanpublic\u00a0CacheErrorHandler\u00a0cacheErrorHandler() {\u00a0 \u00a0\u00a0return\u00a0new\u00a0CacheErrorHandler() {\u00a0 \u00a0 \u00a0 \u00a0\u00a0&#064;Override\u00a0 \u00a0 \u00a0 \u00a0\u00a0public\u00a0void\u00a0handleCacheGetError(RuntimeException exception, Cache cache,\u00a0Object\u00a0key) {\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 log.error(&#034;\u7f13\u5b58\u83b7\u53d6\u9519\u8bef: {}&#034;, exception.getMessage());\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\/\/ \u7ee7\u7eed\u629b\u51fa\u5f02\u5e38\u6216\u8fd4\u56de\u9ed8\u8ba4\u503c\u00a0 \u00a0 \u00a0 \u00a0 }\u00a0 \u00a0 \u00a0 \u00a0\u00a0\/\/ \u5176\u4ed6\u9519\u8bef\u5904\u7406\u65b9\u6cd5&#8230;\u00a0 \u00a0 };}<\/p>\n<li>\u907f\u514d\u7f13\u5b58\u96ea\u5d29\n<ul>\n<li>\n<p>\u4e3a\u4e0d\u540c\u7f13\u5b58\u9879\u8bbe\u7f6e\u968f\u673a\u8fc7\u671f\u65f6\u95f4<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528\u591a\u7ea7\u7f13\u5b58\u67b6\u6784<\/p>\n<\/li>\n<li>\n<p>\u5b9e\u73b0\u7f13\u5b58\u9884\u70ed\u548c\u5feb\u901f\u5931\u8d25\u673a\u5236<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<p>&#x1f4da; \u603b\u7ed3\u00a0<\/p>\n<p>\u7f13\u5b58\u662f\u63d0\u5347Spring Boot\u5e94\u7528\u6027\u80fd\u7684\u6709\u6548\u624b\u6bb5&#xff0c;\u4f46\u9700\u8981\u5408\u7406\u8bbe\u8ba1\u548c\u4f7f\u7528\u3002\u672c\u6587\u4ecb\u7ecd\u4e86Spring Boot\u4e2d\u7684\u9ad8\u7ea7\u7f13\u5b58\u7b56\u7565&#xff0c;\u5305\u62ec\u591a\u7ea7\u7f13\u5b58\u3001\u7f13\u5b58\u7a7f\u900f\u9632\u62a4\u3001\u7f13\u5b58\u9884\u70ed\u3001\u8fc7\u671f\u7b56\u7565\u7b49&#xff0c;\u5e76\u901a\u8fc7\u5b9e\u6218\u6848\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u5e94\u7528\u8fd9\u4e9b\u7b56\u7565\u3002\u901a\u8fc7\u8fd9\u4e9b\u6700\u4f73\u5b9e\u8df5&#xff0c;\u4f60\u53ef\u4ee5\u6784\u5efa\u66f4\u9ad8\u6548\u3001\u66f4\u53ef\u9760\u7684\u7f13\u5b58\u7cfb\u7edf&#xff0c;\u63d0\u5347\u5e94\u7528\u6027\u80fd\u548c\u7528\u6237\u4f53\u9a8c\u3002<\/p>\n<p>\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u7406\u89e3\u548c\u4f18\u5316Spring Boot\u7f13\u5b58\u6709\u6240\u5e2e\u52a9\u3002\u5982\u679c\u4f60\u6709\u4efb\u4f55\u95ee\u9898\u6216\u5efa\u8bae&#xff0c;\u6b22\u8fce\u5728\u8bc4\u8bba\u533a\u7559\u8a00\u8ba8\u8bba&#xff01;<\/p>\n<p>&#x1f4d6; \u53c2\u8003\u8d44\u6599<\/p>\n<ul>\n<li>\n<p>Spring \u5b98\u65b9\u6587\u6863 \u00a0<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 https:\/\/docs.spring.io\/spring-boot\/reference\/io\/caching.html#io.caching<\/p>\n<\/li>\n<li>\n<p>Spring Boot \u5b98\u65b9\u6587\u6863<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0https:\/\/docs.spring.io\/spring-boot\/docs\/current\/reference\/html\/features.html<\/p>\n<\/li>\n<li>\n<p>Caffeine \u7f13\u5b58\u6587\u6863<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0https:\/\/github.com\/ben-manes\/caffeine<\/p>\n<\/li>\n<li>\n<p>Redis \u5b98\u65b9\u6587\u6863<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0https:\/\/redis.io\/documentation<\/p>\n<\/li>\n<li>\n<p>Guava \u5e03\u9686\u8fc7\u6ee4\u5668\u6587\u6863<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0https:\/\/guava.dev\/releases\/snapshot-jre\/api\/docs\/com\/google\/common\/hash\/BloomFilter.html<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb275\u6b21\uff0c\u70b9\u8d5e9\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86SpringBoot\u4e2d\u7684\u9ad8\u7ea7\u7f13\u5b58\u7b56\u7565\u4e0e\u5e94\u7528\u5b9e\u8df5\u3002\u9996\u5148\u8bb2\u89e3\u4e86\u57fa\u7840\u7f13\u5b58\u914d\u7f6e\uff0c\u5305\u62ec@Cacheable\u3001@CacheEvict\u7b49\u6838\u5fc3\u6ce8\u89e3\u7684\u4f7f\u7528\u3002\u91cd\u70b9\u9610\u8ff0\u4e86\u591a\u7ea7\u7f13\u5b58\u67b6\u6784\u8bbe\u8ba1\uff08\u672c\u5730Caffeine+\u5206\u5e03\u5f0fRedis\uff09\u3001\u7f13\u5b58\u7a7f\u900f\u9632\u62a4\uff08\u5e03\u9686\u8fc7\u6ee4\u5668\/\u7a7a\u503c\u7f13\u5b58\uff09\u3001\u7f13\u5b58\u9884\u70ed\u673a\u5236\u548c\u8fc7\u671f\u7b56\u7565\u4f18\u5316\u7b49\u9ad8\u7ea7\u6280\u672f\u3002\u901a\u8fc7\u7535\u5546\u5546\u54c1\u8be6\u60c5\u9875\u7684\u5b9e\u6218\u6848\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u9488\u5bf9\u4e0d\u540c\u4e1a\u52a1\u573a\u666f\u8bbe\u8ba1\u7f13\u5b58\u7c92\u5ea6\u3001\u952e\u547d\u540d\u89c4\u8303\u548c\u4e00\u81f4\u6027\u4fdd\u969c\u65b9\u6848\u3002\u6587\u7ae0\u8fd8\u63d0\u4f9b\u4e86\u7f13\u5b58\u76d1\u63a7\u3001\u5f02\u5e38\u5904\u7406\u548c\u96ea\u5d29\u9632\u62a4\u7b49\u6700\u4f73\u5b9e\u8df5\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u6784\u5efa\u9ad8\u6548\u53ef\u9760\u7684\u7f13\u5b58\u7cfb\u7edf\uff0c\u6709\u6548\u63d0\u5347\u5e94\u7528\u6027\u80fd\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[105,101,98,100,188,398],"topic":[],"class_list":["post-52343","post","type-post","status-publish","format-standard","hentry","category-server","tag-redis","tag-spring","tag-spring-boot","tag-100","tag-188","tag-398"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Spring Boot \u9ad8\u7ea7\u7f13\u5b58\u7b56\u7565\uff1a\u6253\u9020\u9ad8\u6027\u80fd\u5e94\u7528\u7684\u79d8\u5bc6\u6b66\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/52343.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring Boot \u9ad8\u7ea7\u7f13\u5b58\u7b56\u7565\uff1a\u6253\u9020\u9ad8\u6027\u80fd\u5e94\u7528\u7684\u79d8\u5bc6\u6b66\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb275\u6b21\uff0c\u70b9\u8d5e9\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86SpringBoot\u4e2d\u7684\u9ad8\u7ea7\u7f13\u5b58\u7b56\u7565\u4e0e\u5e94\u7528\u5b9e\u8df5\u3002\u9996\u5148\u8bb2\u89e3\u4e86\u57fa\u7840\u7f13\u5b58\u914d\u7f6e\uff0c\u5305\u62ec@Cacheable\u3001@CacheEvict\u7b49\u6838\u5fc3\u6ce8\u89e3\u7684\u4f7f\u7528\u3002\u91cd\u70b9\u9610\u8ff0\u4e86\u591a\u7ea7\u7f13\u5b58\u67b6\u6784\u8bbe\u8ba1\uff08\u672c\u5730Caffeine+\u5206\u5e03\u5f0fRedis\uff09\u3001\u7f13\u5b58\u7a7f\u900f\u9632\u62a4\uff08\u5e03\u9686\u8fc7\u6ee4\u5668\/\u7a7a\u503c\u7f13\u5b58\uff09\u3001\u7f13\u5b58\u9884\u70ed\u673a\u5236\u548c\u8fc7\u671f\u7b56\u7565\u4f18\u5316\u7b49\u9ad8\u7ea7\u6280\u672f\u3002\u901a\u8fc7\u7535\u5546\u5546\u54c1\u8be6\u60c5\u9875\u7684\u5b9e\u6218\u6848\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u9488\u5bf9\u4e0d\u540c\u4e1a\u52a1\u573a\u666f\u8bbe\u8ba1\u7f13\u5b58\u7c92\u5ea6\u3001\u952e\u547d\u540d\u89c4\u8303\u548c\u4e00\u81f4\u6027\u4fdd\u969c\u65b9\u6848\u3002\u6587\u7ae0\u8fd8\u63d0\u4f9b\u4e86\u7f13\u5b58\u76d1\u63a7\u3001\u5f02\u5e38\u5904\u7406\u548c\u96ea\u5d29\u9632\u62a4\u7b49\u6700\u4f73\u5b9e\u8df5\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u6784\u5efa\u9ad8\u6548\u53ef\u9760\u7684\u7f13\u5b58\u7cfb\u7edf\uff0c\u6709\u6548\u63d0\u5347\u5e94\u7528\u6027\u80fd\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/52343.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-11T05:34:17+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/52343.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/52343.html\",\"name\":\"Spring Boot \u9ad8\u7ea7\u7f13\u5b58\u7b56\u7565\uff1a\u6253\u9020\u9ad8\u6027\u80fd\u5e94\u7528\u7684\u79d8\u5bc6\u6b66\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-08-11T05:34:17+00:00\",\"dateModified\":\"2025-08-11T05:34:17+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/52343.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/52343.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/52343.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Spring Boot \u9ad8\u7ea7\u7f13\u5b58\u7b56\u7565\uff1a\u6253\u9020\u9ad8\u6027\u80fd\u5e94\u7528\u7684\u79d8\u5bc6\u6b66\u5668\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring Boot \u9ad8\u7ea7\u7f13\u5b58\u7b56\u7565\uff1a\u6253\u9020\u9ad8\u6027\u80fd\u5e94\u7528\u7684\u79d8\u5bc6\u6b66\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/52343.html","og_locale":"zh_CN","og_type":"article","og_title":"Spring Boot \u9ad8\u7ea7\u7f13\u5b58\u7b56\u7565\uff1a\u6253\u9020\u9ad8\u6027\u80fd\u5e94\u7528\u7684\u79d8\u5bc6\u6b66\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb275\u6b21\uff0c\u70b9\u8d5e9\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86SpringBoot\u4e2d\u7684\u9ad8\u7ea7\u7f13\u5b58\u7b56\u7565\u4e0e\u5e94\u7528\u5b9e\u8df5\u3002\u9996\u5148\u8bb2\u89e3\u4e86\u57fa\u7840\u7f13\u5b58\u914d\u7f6e\uff0c\u5305\u62ec@Cacheable\u3001@CacheEvict\u7b49\u6838\u5fc3\u6ce8\u89e3\u7684\u4f7f\u7528\u3002\u91cd\u70b9\u9610\u8ff0\u4e86\u591a\u7ea7\u7f13\u5b58\u67b6\u6784\u8bbe\u8ba1\uff08\u672c\u5730Caffeine+\u5206\u5e03\u5f0fRedis\uff09\u3001\u7f13\u5b58\u7a7f\u900f\u9632\u62a4\uff08\u5e03\u9686\u8fc7\u6ee4\u5668\/\u7a7a\u503c\u7f13\u5b58\uff09\u3001\u7f13\u5b58\u9884\u70ed\u673a\u5236\u548c\u8fc7\u671f\u7b56\u7565\u4f18\u5316\u7b49\u9ad8\u7ea7\u6280\u672f\u3002\u901a\u8fc7\u7535\u5546\u5546\u54c1\u8be6\u60c5\u9875\u7684\u5b9e\u6218\u6848\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u9488\u5bf9\u4e0d\u540c\u4e1a\u52a1\u573a\u666f\u8bbe\u8ba1\u7f13\u5b58\u7c92\u5ea6\u3001\u952e\u547d\u540d\u89c4\u8303\u548c\u4e00\u81f4\u6027\u4fdd\u969c\u65b9\u6848\u3002\u6587\u7ae0\u8fd8\u63d0\u4f9b\u4e86\u7f13\u5b58\u76d1\u63a7\u3001\u5f02\u5e38\u5904\u7406\u548c\u96ea\u5d29\u9632\u62a4\u7b49\u6700\u4f73\u5b9e\u8df5\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u6784\u5efa\u9ad8\u6548\u53ef\u9760\u7684\u7f13\u5b58\u7cfb\u7edf\uff0c\u6709\u6548\u63d0\u5347\u5e94\u7528\u6027\u80fd\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/52343.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-08-11T05:34:17+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/52343.html","url":"https:\/\/www.wsisp.com\/helps\/52343.html","name":"Spring Boot \u9ad8\u7ea7\u7f13\u5b58\u7b56\u7565\uff1a\u6253\u9020\u9ad8\u6027\u80fd\u5e94\u7528\u7684\u79d8\u5bc6\u6b66\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-08-11T05:34:17+00:00","dateModified":"2025-08-11T05:34:17+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/52343.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/52343.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/52343.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Spring Boot \u9ad8\u7ea7\u7f13\u5b58\u7b56\u7565\uff1a\u6253\u9020\u9ad8\u6027\u80fd\u5e94\u7528\u7684\u79d8\u5bc6\u6b66\u5668"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/52343","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=52343"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/52343\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=52343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=52343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=52343"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=52343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}