当前位置: 首页 > 面试题库 >

JHipster Redis集成元素未绑定错误

夹谷斌蔚
2023-03-14
问题内容

所以我一直在遵循这个请求,将Redis集成到jhipster生成器上:https :
//github.com/jhipster/generator-
jhipster/pull/10057/commits/cd2f2865d35dfd77624dd3a38ed32822e895539d

这是我配置的:

ApplicationProperties.java:

package com.xxx.xxx.config;

import org.springframework.boot.context.properties.ConfigurationProperties;

import io.github.jhipster.config.JHipsterDefaults;

/**
 * <p>
 * Properties are configured in the {@code application.yml} file.
 * See {@link io.github.jhipster.config.JHipsterProperties} for a good example.
 */
@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.ejs:

<%_ 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);
            }


            <%_ if (enableHibernateCache) { _%>
            @Bean
            public HibernatePropertiesCustomizer hibernatePropertiesCustomizer(javax.cache.CacheManager cm) {
                return hibernateProperties -> hibernateProperties.put(ConfigSettings.CACHE_MANAGER, cm);
            }
            <%_ } _%>

            @Bean
            public JCacheManagerCustomizer cacheManagerCustomizer() {
                return cm -> {
                    <%_ if (!skipUserManagement || (authenticationType === 'oauth2' && databaseType !== 'no')) { _%>
                    createCache(cm, <%=packageName%>.repository<% if (reactive) { %>.reactive<% } %>.UserRepository.USERS_BY_LOGIN_CACHE);
                    createCache(cm, <%=packageName%>.repository<% if (reactive) { %>.reactive<% } %>.UserRepository.USERS_BY_EMAIL_CACHE);
                        <%_ if (enableHibernateCache) { _%>
                    createCache(cm, <%=packageName%>.domain.<%= asEntity('User') %>.class.getName());
                    createCache(cm, <%=packageName%>.domain.Authority.class.getName());
                    createCache(cm, <%=packageName%>.domain.<%= asEntity('User') %>.class.getName() + ".authorities");
                            <%_ if (authenticationType === 'session') { _%>
                    createCache(cm, <%=packageName%>.domain.PersistentToken.class.getName());
                    createCache(cm, <%=packageName%>.domain.<%= asEntity('User') %>.class.getName() + ".persistentTokens");
                            <%_ } _%>
                        <%_ } _%>
                    <%_ } _%>
                    // jhipster-needle-redis-add-entry
                };
            }

            private void createCache(javax.cache.CacheManager cm, String cacheName) {
                javax.cache.Cache<Object, Object> cache = cm.getCache(cacheName);
                if (cache != null) {
                    cm.destroyCache(cacheName);
                }
                cm.createCache(cacheName, jcacheConfiguration);
            }
        <%_ } _%>

application.yml:

# ===================================================================
# 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

我的最后一个问题是在ApplicationProperties.java中,特别是:

private String server = JHipsterDefaults.Cache.Redis.server;
private int expiration = JHipsterDefaults.Cache.Redis.expiration;

哪个状态:Redis无法解析或不是字段Java:

[ERROR]   symbol:   variable Redis
[ERROR]   location: interface io.github.jhipster.config.JHipsterDefaults.Cache

UPDATE :解决了无效字段-解决方案:

private String server = "redis://localhost:6379";
private int expiration = 300;

立即发布 (元素[]未绑定):

***************************
APPLICATION FAILED TO START
***************************

Description:

Binding to target [Bindable@77574136 type = io.github.jhipster.config.JHipsterProperties, value = 'provided', annotations = array<Annotation>[@org.springframework.boot.context.properties.ConfigurationProperties(value=jhipster, prefix=jhipster, ignoreInvalidFields=false, ignoreUnknownFields=false)]] failed:

    Property: jhipster.cache.redis.expiration
    Value: 3600
    Origin: class path resource [config/application-dev.yml]:101:19
    Reason: The elements [jhipster.cache.redis.expiration] were left unbound.

Action:

Update your application's configuration

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  13.591 s

UPDATE :元素[]未绑定已解决-解决方案:

application:
    redis: # Redis configuration
      expiration: 300 # time



jhipster:
  # CORS is disabled by default on microservices, as you should access them through a gateway.
  # If you want to enable it, please uncomment the configuration below.
  # cors:
  #     allowed-origins: "*"
  #     allowed-methods: "*"
  #     allowed-headers: "*"
  #     exposed-headers: "Authorization,Link,X-Total-Count"
  #     allow-credentials: true
  #     max-age: 1800
  mail: # specific JHipster mail property, for standard properties see MailProperties
    from: appname@localhost
    base-url: http://127.0.0.1:8081
  metrics:
    logs: # Reports metrics in the logs
      enabled: false
      report-frequency: 60 # in seconds
  logging:
    use-json-format: false # By default, logs are not in Json format
    logstash: # Forward logs to logstash over a socket, used by LoggingConfiguration
      enabled: false
      host: localhost
      port: 5000
      queue-size: 512

  # ===================================================================
  # 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:
    redis:
      expiration: 300

更详细的StackTrace:

2019-07-17 10:58:35.205 ERROR 87330 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cachesEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/cache/CachesEndpointAutoConfiguration.class]: Unsatisfied dependency expressed through method 'cachesEndpoint' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cacheManager' defined in class path resource [org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.class]: Unsatisfied dependency expressed through method 'cacheManager' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jCacheCacheManager' defined in class path resource [org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.cache.CacheManager]: Factory method 'jCacheCacheManager' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheConfiguration' defined in file [../config/CacheConfiguration.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.package.project.config.CacheConfiguration$$EnhancerBySpringCGLIB$$2ce84f38]: Constructor threw exception; nested exception is org.redisson.client.RedisConnectionException: Unable to connect to Redis server: localhost/127.0.0.1:6379

Caused by: java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cachesEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/cache/CachesEndpointAutoConfiguration.class]: Unsatisfied dependency expressed through method 'cachesEndpoint' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cacheManager' defined in class path resource [org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.class]: Unsatisfied dependency expressed through method 'cacheManager' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jCacheCacheManager' defined in class path resource [org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.cache.CacheManager]: Factory method 'jCacheCacheManager' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheConfiguration' defined in file [../config/CacheConfiguration.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.package.project.config.CacheConfiguration$$EnhancerBySpringCGLIB$$2ce84f38]: Constructor threw exception; nested exception is org.redisson.client.RedisConnectionException: Unable to connect to Redis server: localhost/127.0.0.1:6379

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cachesEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/cache/CachesEndpointAutoConfiguration.class]: Unsatisfied dependency expressed through method 'cachesEndpoint' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cacheManager' defined in class path resource [org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.class]: Unsatisfied dependency expressed through method 'cacheManager' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jCacheCacheManager' defined in class path resource [org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.cache.CacheManager]: Factory method 'jCacheCacheManager' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheConfiguration' defined in file [../config/CacheConfiguration.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.package.project.config.CacheConfiguration$$EnhancerBySpringCGLIB$$2ce84f38]: Constructor threw exception; nested exception is org.redisson.client.RedisConnectionException: Unable to connect to Redis server: localhost/127.0.0.1:6379

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cachesEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/cache/CachesEndpointAutoConfiguration.class]: Unsatisfied dependency expressed through method 'cachesEndpoint' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cacheManager' defined in class path resource [org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.class]: Unsatisfied dependency expressed through method 'cacheManager' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jCacheCacheManager' defined in class path resource [org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.cache.CacheManager]: Factory method 'jCacheCacheManager' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheConfiguration' defined in file [../config/CacheConfiguration.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.package.project.config.CacheConfiguration$$EnhancerBySpringCGLIB$$2ce84f38]: Constructor threw exception; nested exception is org.redisson.client.RedisConnectionException: Unable to connect to Redis server: localhost/127.0.0.1:6379

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cachesEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/cache/CachesEndpointAutoConfiguration.class]: Unsatisfied dependency expressed through method 'cachesEndpoint' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cacheManager' defined in class path resource [org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.class]: Unsatisfied dependency expressed through method 'cacheManager' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jCacheCacheManager' defined in class path resource [org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.cache.CacheManager]: Factory method 'jCacheCacheManager' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheConfiguration' defined in file [../config/CacheConfiguration.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.package.project.config.CacheConfiguration$$EnhancerBySpringCGLIB$$2ce84f38]: Constructor threw exception; nested exception is org.redisson.client.RedisConnectionException: Unable to connect to Redis server: localhost/127.0.0.1:6379

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cacheManager' defined in class path resource [org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.class]: Unsatisfied dependency expressed through method 'cacheManager' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jCacheCacheManager' defined in class path resource [org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.cache.CacheManager]: Factory method 'jCacheCacheManager' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheConfiguration' defined in file [../config/CacheConfiguration.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.package.project.config.CacheConfiguration$$EnhancerBySpringCGLIB$$2ce84f38]: Constructor threw exception; nested exception is org.redisson.client.RedisConnectionException: Unable to connect to Redis server: localhost/127.0.0.1:6379

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jCacheCacheManager' defined in class path resource [org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.cache.CacheManager]: Factory method 'jCacheCacheManager' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheConfiguration' defined in file [../config/CacheConfiguration.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.package.project.config.CacheConfiguration$$EnhancerBySpringCGLIB$$2ce84f38]: Constructor threw exception; nested exception is org.redisson.client.RedisConnectionException: Unable to connect to Redis server: localhost/127.0.0.1:6379

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.cache.CacheManager]: Factory method 'jCacheCacheManager' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheConfiguration' defined in file [../config/CacheConfiguration.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.package.project.config.CacheConfiguration$$EnhancerBySpringCGLIB$$2ce84f38]: Constructor threw exception; nested exception is org.redisson.client.RedisConnectionException: Unable to connect to Redis server: localhost/127.0.0.1:6379

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheConfiguration' defined in file [../config/CacheConfiguration.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.package.project.config.CacheConfiguration$$EnhancerBySpringCGLIB$$2ce84f38]: Constructor threw exception; nested exception is org.redisson.client.RedisConnectionException: Unable to connect to Redis server: localhost/127.0.0.1:6379

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.package.project.config.CacheConfiguration$$EnhancerBySpringCGLIB$$2ce84f38]: Constructor threw exception; nested exception is org.redisson.client.RedisConnectionException: Unable to connect to Redis server: localhost/127.0.0.1:6379

Caused by: org.redisson.client.RedisConnectionException: Unable to connect to Redis server: localhost/127.0.0.1:6379

Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/127.0.0.1:6379

Caused by: java.net.ConnectException: Connection refused
    ... 12 common frames omitted

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  17.977 s
[INFO] Finished at: 2019-07-17T10:58:36-07:00
[INFO] ------------------------------------------------------------------------

最终更新:REDIS集成成功

redis-server
./mvnw

问题答案:

该消息显示是The elements [jhipster.cache.redis.expiration] were left unbound因为该属性在JhipsterProperties中不存在。您应该删除该值和配置application.redis.expiration,而不是



 类似资料:
  • 如何在JavaSpringBoot应用程序中从配置yml文件加载对象列表? 我已经尝试了几个来源: 配置-属性-在-Spring-引导 Spring Boot配置属性示例 SpringBoot 2的元素没有绑定 堆栈:Java11,SpringBoot 2.1.4,Lombok,. yml格式的配置文件。 我尝试实现简单的@Component,它将从配置文件加载数据。 配置值为: 用于数据加载的J

  • 我的Spring Boot应用程序有一个文件application.yml,它不愿意运行。 根据日志,元素[simulator.geo.b12,simulator.geo.b13,simulator.geo.b21,simulator.geo.c6,simulator.geo.host]未绑定的原因。然而,这个属性是在application.yml设置的,编译器甚至会返回它的值。 如果有人能帮我解

  • 问题内容: 我正在尝试找出如何阻止 DOM 元素以角度限制来自合并范围的数据。 我知道您可以使用if语句和所有方法来执行此操作,但是是否有一种真正而永久的方法来停止以角度绑定元素但保留添加的内容? 所以说我有这个 我更改了模型,以便div更改为此。 然后,我单击将其解除绑定的按钮,因此,如果将模型更改为,则不需要与以前相同。这个 我知道还有许多其他方法可以执行此操作,但是我不知道要真正地解除绑定元

  • 问题内容: 我在“ tx:annotation-driven”行上收到上述错误,但是我在Bean文件的顶部声明了名称空间,为什么以下XML导致此错误? 问题答案: 就像其他xmlns:定义一样,您需要一个xmlns:tx

  • 本文向大家介绍aurelia 绑定到选择元素,包括了aurelia 绑定到选择元素的使用技巧和注意事项,需要的朋友参考一下 示例 字符串数组 在选择下拉列表中选择一个值并提供字符串数组时,所选值将作为字符串绑定到选择元素的value属性,我们可以使用字符串插值显示该字符串。 对象数组 与上面的示例不同,当提供对象数组时,在下拉列表中选择一个值时,绑定到该特定选项的模型就是所提供的对象。      

  • 英文原文:http://emberjs.com/guides/templates/binding-element-attributes/ 除了普通文本,你可能也希望在模板中包含可以将其属性绑定到控制器的HTML元素。 例如,想象一下你的控制器中包含这样一个属性,它包含指向一幅图像的URL地址: 1 2 3 <div id="logo"> <img {{bind-attr src=logoUr