title: The background cache eviction process was unable to free [10] percent of the cache for context
body: <p>I am trying to deploy spring boot application on my server. I have kept my WAR file on webapps folder inside Tomcat. </p>
  
  <h2>pom.xml</h2>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
  &lt;groupId&gt;com.privilance&lt;/groupId&gt;
  &lt;artifactId&gt;privilance_survey&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;packaging&gt;war&lt;/packaging&gt;
  
  &lt;name&gt;privilance_survey&lt;/name&gt;
  &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  
  &lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;version&gt;1.5.2.RELEASE&lt;/version&gt;
      &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
  &lt;/parent&gt;
  
  &lt;properties&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
      &lt;java.version&gt;1.8&lt;/java.version&gt;
  &lt;/properties&gt;
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;mysql&lt;/groupId&gt;
          &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
          &lt;scope&gt;runtime&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;net.sf.barcode4j&lt;/groupId&gt;
          &lt;artifactId&gt;barcode4j&lt;/artifactId&gt;
          &lt;version&gt;2.1&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!--     
      &lt;dependency&gt;
          &lt;groupId&gt;net.sourceforge.nekohtml&lt;/groupId&gt;
          &lt;artifactId&gt;nekohtml&lt;/artifactId&gt;
          &lt;version&gt;1.9.21&lt;/version&gt;&lt;!--$NO-MVN-MAN-VER$--&gt;
      &lt;/dependency&gt;
      &lt;!-- https://mvnrepository.com/artifact/org.apache.pdfbox/pdfbox --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.pdfbox&lt;/groupId&gt;
          &lt;artifactId&gt;pdfbox&lt;/artifactId&gt;
          &lt;version&gt;2.0.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!-- https://mvnrepository.com/artifact/commons-logging/commons-logging --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;commons-logging&lt;/groupId&gt;
          &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
          &lt;version&gt;1.1.1&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.itextpdf&lt;/groupId&gt;
          &lt;artifactId&gt;itextpdf&lt;/artifactId&gt;
          &lt;version&gt;5.5.11&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  &lt;build&gt;
      &lt;finalName&gt;privilance&lt;/finalName&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p></p>
  
  <p>I did some search and find out some people solved their problem by adding this bean.</p>
  
  <pre><code>@Bean
  public EmbeddedServletContainerFactory servletContainer() {
      TomcatEmbeddedServletContainerFactory tomcatFactory = new TomcatEmbeddedServletContainerFactory() {
          @Override
          protected void postProcessContext(Context context) {
              final int cacheSize = 40 * 1024;
              StandardRoot standardRoot = new StandardRoot(context);
              standardRoot.setCacheMaxSize(cacheSize);
              context.setResources(standardRoot); // This is what made it work in my case.
  
              logger.info(String.format("New cache size (KB): %d", context.getResources().getCacheMaxSize()));
          }
      };
      return tomcatFactory;
  }
  </code></pre>
  
  <p>But in my case this is also not working. Whenever I run <code>localhost:8080/privilance</code> on my browser says:</p>
  
  <blockquote>
    <p>The origin server did not find a current representation for the target
    resource or is not willing to disclose that one exists.</p>
  </blockquote>
  
  <p>and in my cmd prompt says:</p>
  
  <blockquote>
    <p>the background cache eviction process was unable to free [10] percent
    of the cache for context. consider increasing maximum size of the
    cache ....approximately [9285] kb of data remained on the cache.</p>
  </blockquote>