Search code examples
javaspring-bootdockerdocker-composememcached

Memcached configuration in springboot app


I'm trying to CI a Java SpringBoot app, the app is making use of memcached. pom.xml dependency:

<dependency>
  <groupId>io.sixhours</groupId>
  <artifactId>memcached-spring-boot-starter</artifactId>
  <version>1.3.1</version>
</dependency> 

I'v created a docker-compose.yaml file with memcached container, app container and nginx as reverse proxy all running on the same network ci_network:

version: '3'

services:
  memcached:
    image: memcached:latest
    ports:
      - "11211:11211"
    networks:
      - ci_network
    healthcheck:
      test: ["CMD", "echo", "stats", "|", "nc", "localhost", "11211"]
      interval: 10s
      timeout: 2s
      retries: 5
  
  # Backend - ted-search app
  app:
    image: ted-search:latest
    depends_on:
      memcached:
        condition: service_healthy
    networks:
      - ci_network

  # Reverse Proxy - Nginx
  proxy:
    build:
      context: .
      dockerfile: Dockerfile.nginx    
    ports:
      - "80:80"
    depends_on:
      - app    
    networks:
      - ci_network

networks:
  ci_network:
    external: true

I've configured the application.properties file to enable memcached as follows:

server.port: 9191

spring.cache.type=GENERIC

# MEMCACHED CACHE
memcached.cache.servers: memcached:11211
memcached.cache.mode: static
memcached.cache.expirations: 3600, oembed:3600
memcached.cache.prefix: memcached:spring-boot
memcached.cache.namespace: namespace
memcached.cache.protocol: text


#Metrics related configurations
management.endpoint.metrics.enabled=true
management.endpoints.web.exposure.include=*
management.endpoint.prometheus.enabled=true
management.metrics.export.prometheus.enabled=true

management.metrics.distribution.percentiles-histogram.http.server.requests: true
management.metrics.distribution.sla.server.requests: 450ms

for some reason every time I'm running my docker compose orchestration the app is crashing with the following error:

18:21:03  ted-search_master-app-1        | org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheAutoConfigurationValidator' defined in class path resource [org/springframework/boot/autoconfigure/cache/CacheAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: No cache manager could be auto-configured, check your configuration (caching type is 'GENERIC')

what am I doing wrong?


Solution

  • Could you try removing the spring.cache.type=GENERIC from your application.properties and try again.

    The issue you have reported is related to the cache configuration in the application itself.

    In case the spring.cache.type is specified, the memcached-spring-boot-starter library will skip its auto-configuration and use Spring Boot cache auto-configuration instead. Being the GENERIC cache type is missing proper configuration (org.springframework.cache.Cache bean), the application startup will fail.

    You should also consider upgrading the memcached-spring-boot-starter to the latest version 2.5.0.