Проблема конфигурации кэша микросервиса Jhipster с Memcached - PullRequest
0 голосов
/ 07 марта 2020

Я сгенерировал приложение для микросервиса и выбрал memcached в качестве поставщика кеша. Ниже приведено тело файла yo-r c. json.

    {
  "generator-jhipster": {
    "promptValues": {
      "packageName": "org.aust.ugadmission"
    },
    "jhipsterVersion": "6.7.1",
    "applicationType": "microservice",
    "baseName": "UgAdmission",
    "packageName": "org.aust.ugadmission",
    "packageFolder": "org/aust/ugadmission",
    "serverPort": "8081",
    "authenticationType": "uaa",
    "uaaBaseName": "AustUAA",
    "cacheProvider": "memcached",
    "enableHibernateCache": false,
    "websocket": false,
    "databaseType": "sql",
    "devDatabaseType": "oracle",
    "prodDatabaseType": "oracle",
    "searchEngine": false,
    "messageBroker": false,
    "serviceDiscoveryType": "eureka",
    "buildTool": "maven",
    "enableSwaggerCodegen": true,
    "jwtSecretKey": "YThmYTdiODlmYTNlNDNlMzZkNjU2Yzk4MDlkNjZkMzg2YmIwZTQ5NDlmNzBhZjMyZjVhNGYwMWIyNTc3ODVlN2FjNGIyN2Q1YmFhOGNmODU3OGFjMzc1MTUyMjhhMjMzMWI5ZjBhMmFkODExM2ZiOGU5MWMyOTY3MTRjNTdmYjE=",
    "embeddableLaunchScript": false,
    "creationTimestamp": 1583595983988,
    "testFrameworks": ["gatling", "cucumber"],
    "jhiPrefix": "jhi",
    "entitySuffix": "",
    "dtoSuffix": "DTO",
    "otherModules": [],
    "enableTranslation": false,
    "clientPackageManager": "npm",
    "blueprints": [],
    "skipClient": true,
    "skipUserManagement": true
  }
}

Но я вижу, что сгенерированный файл CacheConfig имеет некоторые зависимости от UserRepository .

Ниже приведен файл CacheConfig.

package org.aust.ugadmission.config;

import org.aust.ugadmission.repository.UserRepository;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.support.NoOpCacheManager;
import org.springframework.context.annotation.*;

import com.google.code.ssm.CacheFactory;
import com.google.code.ssm.config.DefaultAddressProvider;
import com.google.code.ssm.providers.xmemcached.MemcacheClientFactoryImpl;
import com.google.code.ssm.spring.SSMCache;
import com.google.code.ssm.spring.SSMCacheManager;

import io.github.jhipster.config.JHipsterProperties;

@Configuration
@EnableCaching
public class CacheConfiguration {

    private final Logger log = LoggerFactory.getLogger(CacheConfiguration.class);

    @Bean
    public CacheManager memcachedCacheManager(JHipsterProperties jHipsterProperties, List<CacheFactory> caches)
        throws Exception {

        if (!jHipsterProperties.getCache().getMemcached().isEnabled()) {
            // Note that Memcached cannot work with Spring Boot devtools
            // So it should be disabled in development mode
            log.debug("Memcached is disabled");
            return new NoOpCacheManager();
        }
        log.debug("Starting Memcached configuration");
        SSMCacheManager cacheManager = new SSMCacheManager();
        List<SSMCache> ssmCaches = new ArrayList<>();
        for (CacheFactory cache : caches) {
            SSMCache ssmCache =
                new SSMCache(cache.getObject(), jHipsterProperties.getCache().getMemcached().getExpiration(),
                    false);

            ssmCaches.add(ssmCache);
        }
        cacheManager.setCaches(ssmCaches);
        return cacheManager;
    }

    @Bean
    public CacheFactory usersByLoginCache(JHipsterProperties jHipsterProperties) {
        return this.createCache(UserRepository.USERS_BY_LOGIN_CACHE, jHipsterProperties);
    }

    @Bean
    public CacheFactory usersByEmailCache(JHipsterProperties jHipsterProperties) {
        return this.createCache(UserRepository.USERS_BY_EMAIL_CACHE, jHipsterProperties);
    }

    private CacheFactory createCache(String cacheName, JHipsterProperties jHipsterProperties) {
        if (!jHipsterProperties.getCache().getMemcached().isEnabled()) {
            // Note that Memcached cannot work with Spring Boot devtools
            // So it should be disabled in development mode
            return null;
        }
        CacheFactory defaultCache = new CacheFactory();
        defaultCache.setCacheName(cacheName);
        defaultCache.setCacheClientFactory(new MemcacheClientFactoryImpl());

        DefaultAddressProvider addressProvider = new DefaultAddressProvider();
        addressProvider.setAddress(jHipsterProperties.getCache().getMemcached().getServers());
        defaultCache.setAddressProvider(addressProvider);

        com.google.code.ssm.providers.CacheConfiguration cacheConfiguration = new com.google.code.ssm.providers
            .CacheConfiguration();
        cacheConfiguration.setConsistentHashing(true);
        cacheConfiguration.setUseBinaryProtocol(jHipsterProperties.getCache().getMemcached().isUseBinaryProtocol());
        defaultCache.setConfiguration(cacheConfiguration);

        return defaultCache;
    }

}

Поскольку файл конфигурации зависит от UserRepository, а файл UserRepository отсутствует. java файл находится в проекте микросервиса, в результате возникают проблемы во время компиляции.

...