0

我正在尝试在春季启动 web 应用程序中遵循使用 bucket4j(速率限制)的jcache(ehcache)使用示例。

这是我特别关注的示例 3,它参考了:

@Inject
private javax.cache.Cache<String, GridBucketState> cache;

可以预见(每次我接近一个弹簧示例时都会发生这种情况)这是空的,并且在@Component org.springframework.web.servlet.HandlerInterceptor 稍后引用时会在 a 中抛出一个 NPE。我不知道为什么,我不知道预计会有什么配置,我不知道如何调试它。

我有一个ehcache.xml

<config xmlns='http://www.ehcache.org/v3'
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:jsr107="http://www.ehcache.org/v3/jsr107"
  xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd
                            http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.0.xsd">
  <cache alias="buckets">
    <expiry>
      <ttl unit="seconds">3600</ttl>
    </expiry>
    <heap unit="entries">1000000</heap>
    <jsr107:mbeans enable-statistics="true"/>
  </cache>
</config>

以及以下行application.properties

spring.cache.jcache.config=classpath:ehcache.xml

有什么建议么?谢谢。

4

0 回答 0