将Redis集成到JHipster CacheConfiguration错误 [英] Integrate Redis to JHipster CacheConfiguration error

查看:428
本文介绍了将Redis集成到JHipster CacheConfiguration错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Github上执行以下拉取请求后,我正在尝试将Redis缓存集成到JHipster生成器: https://github.com/jhipster/generator-jhipster/pull/10057/commits/cd2f2865d35dfd77624dd3a38ed32822e895539d#

I'm trying to integrate redis cache to JHipster generator following this pull request on Github: https://github.com/jhipster/generator-jhipster/pull/10057/commits/cd2f2865d35dfd77624dd3a38ed32822e895539d#

我在构建项目时收到此错误:

I receive this error while building my project:

[ERROR]   symbol:   method getRedis()
[ERROR]   location: class io.github.jhipster.config.JHipsterProperties.Cache
[ERROR] ../config/CacheConfiguration.java:[61,139] cannot find symbol

JHipsterProperties.CacheJava(67108964)类型的getRedis()方法未定义

The method getRedis() is undefined for the type JHipsterProperties.CacheJava(67108964)

在哪里定义了getRedis()?

Where is getRedis() defined?

CacheConfiguration方法:

CacheConfiguration method in CacheConfiguration.java:

private final javax.cache.configuration.Configuration<Object, Object> jcacheConfiguration;

            public CacheConfiguration(JHipsterProperties jHipsterProperties) {
                MutableConfiguration<Object, Object> jcacheConfig = new MutableConfiguration<>();
                Config config = new Config();
                config.useSingleServer()
                .setAddress(jHipsterProperties.getCache().getRedis().getServer())
                .setSubscriptionConnectionMinimumIdleSize(1)
                .setSubscriptionConnectionPoolSize(50)
                .setConnectionMinimumIdleSize(24)
                .setConnectionPoolSize(64)
                .setDnsMonitoringInterval(5000)
                .setIdleConnectionTimeout(10000)
                .setConnectTimeout(10000)
                .setTimeout(3000)
                .setRetryAttempts(3)
                .setRetryInterval(1500)
                .setDatabase(0)
                .setPassword(null)
                .setSubscriptionsPerConnection(5)
                .setClientName(null)
                .setSslEnableEndpointIdentification(true)
                .setSslProvider(SslProvider.JDK)
                .setSslTruststore(null)
                .setSslTruststorePassword(null)
                .setSslKeystore(null)
                .setSslKeystorePassword(null)
                .setPingConnectionInterval(0)
                .setKeepAlive(false)
                .setTcpNoDelay(false);
            jcacheConfig.setStatisticsEnabled(true);
            jcacheConfig.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, jHipsterProperties.getCache().getRedis().getExpiration())));
            jcacheConfiguration = RedissonConfiguration.fromInstance(Redisson.create(config), jcacheConfig);
        }

我是否缺少getRedis()的某些依赖项?

Am I missing some dependencies for getRedis()?

注意:我在build.gradle.ejs中忽略了这个;这会导致问题吗?

Note: I left out this in build.gradle.ejs; would this be causing the problem?

  <%_ if (cacheProvider === 'redis') { _%>
    implementation "org.redisson:redisson"
        <%_ if (enableHibernateCache) { _%>
    implementation "org.hibernate:hibernate-jcache"
        <%_ } _%>
    <%_ } _%>

解决方案?:

ApplicationProperties.java:

ApplicationProperties.java:

@ConfigurationProperties(prefix = "application", ignoreUnknownFields = false)
public class ApplicationProperties {

     private final Redis redis = new Redis();

     public Redis getRedis() {
          return redis;
      }

      public static class Redis {
          private String server = JHipsterDefaults.Cache.Redis.server;
          private int expiration = JHipsterDefaults.Cache.Redis.expiration;

          public String getServer() {
              return server;
          }

          public void setServer(String server) {
              this.server = server;
          }

          public int getExpiration() {
              return expiration;
          }

          public void setExpiration(int expiration) {
              this.expiration = expiration;
          }
      }
}

CacheConfiguration.java

CacheConfiguration.java

 <%_ if (cacheProvider === 'redis') { _%>
        private final javax.cache.configuration.Configuration<Object, Object> jcacheConfiguration;

            public CacheConfiguration(JHipsterProperties jHipsterProperties, ApplicationProperties applicationProperties) {

            MutableConfiguration<Object, Object> jcacheConfig = new MutableConfiguration<>();
            Config config = new Config();
            config.useSingleServer()
                .setAddress(applicationProperties.getRedis().getServer());
                .setSubscriptionConnectionMinimumIdleSize(1)
                .setSubscriptionConnectionPoolSize(50)
                .setConnectionMinimumIdleSize(24)
                .setConnectionPoolSize(64)
                .setDnsMonitoringInterval(5000)
                .setIdleConnectionTimeout(10000)
                .setConnectTimeout(10000)
                .setTimeout(3000)
                .setRetryAttempts(3)
                .setRetryInterval(1500)
                .setDatabase(0)
                .setPassword(null)
                .setSubscriptionsPerConnection(5)
                .setClientName(null)
                .setSslEnableEndpointIdentification(true)
                .setSslProvider(SslProvider.JDK)
                .setSslTruststore(null)
                .setSslTruststorePassword(null)
                .setSslKeystore(null)
                .setSslKeystorePassword(null)
                .setPingConnectionInterval(0)
                .setKeepAlive(false)
                .setTcpNoDelay(false);
            jcacheConfig.setStatisticsEnabled(true);
            jcacheConfig.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, applicationProperties.getRedis().getExpiration())));
            jcacheConfiguration = RedissonConfiguration.fromInstance(Redisson.create(config), jcacheConfig);
        }

application.yml.ejs

application.yml.ejs

# ===================================================================
# Application specific properties
# Add your own application properties here, see the ApplicationProperties class
# to have type-safe configuration, like in the JHipsterProperties above
#
# More documentation is available at:
# https://www.jhipster.tech/common-application-properties/
# ===================================================================

# application:
    application.redis.server: redis://localhost:6379
    application.redis.expiration: 300

推荐答案

您缺少JHipster库中尚未发布的相应更改(位于此

You are missing the respective changes in the JHipster library which are not released yet (located in this pull request).

我的建议(直到发布)是要从

My advice (until it's released) would be to copy the changes (the Redis class and values) from JhipsterProperties.java to your ApplicationProperties.java.

然后,如果需要将值配置为非默认值,则可以在

Then if you need to configure the values to a non-default value, you can do so in your application.yml under the application: key.

最后将ApplicationProperties applicationProperties添加到JhipsterProperties旁边的CacheConfiguration.java中的构造函数中,并从那里引用getRedis().

Lastly add ApplicationProperties applicationProperties to the constructor in CacheConfiguration.java next to JhipsterProperties and reference getRedis() from there.

我相信reddison依赖项也是必需的.

I believe the reddison dependency is also needed.

这篇关于将Redis集成到JHipster CacheConfiguration错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆