Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

353
Vistas
/tmp/tomcat-docbase is always created with a Spring Boot JAR (but not a WAR)

From STS I'm creating a standard Spring Boot 1.5.2 'Web' project. If you run this application you get two directories created - the normal 'base' directory and a 'tomcat-docbase' directory

. . .  4096 Mar 29 10:00 tomcat.2743776473678691880.8080
. . .  4096 Mar 29 10:00 tomcat-docbase.76291847886629412.8080

If I change this project to a WAR project I get only the 'base' directory

. . .   4096 Mar 29 10:06 tomcat.3131223012454570991.8080

It's easy to override the default base directory using

 server.tomcat.basedir=.

however this has no effect on tomcat-docbase. It is possible to override tomcat-docbase programmatically but seems like a hack.

Does anyone think this is a bug?

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Solution: create a folder name as public under your project, in the same folder with your JAR.

Reason: from the springboot code, there is no configuration for docbase folder. but you can create a common root folder in you project folder name as public, static or src/main/webapp, then the springboot will never create temp tomcat-docbase folder for you again.

private static final String[] COMMON_DOC_ROOTS = { "src/main/webapp", "public", "static" }
...
public final File getValidDirectory() {
    File file = this.directory;
    file = (file != null ? file : getWarFileDocumentRoot());
    file = (file != null ? file : getExplodedWarFileDocumentRoot());
    file = (file != null ? file : getCommonDocumentRoot());
    if (file == null && this.logger.isDebugEnabled()) {
        logNoDocumentRoots();
    }
    else if (this.logger.isDebugEnabled()) {
        this.logger.debug("Document root: " + file);
    }
    return file;
}
...
private File getCommonDocumentRoot() {
    for (String commonDocRoot : COMMON_DOC_ROOTS) {
        File root = new File(commonDocRoot);
        if (root.exists() && root.isDirectory()) {
            return root.getAbsoluteFile();
        }
    }
    return null;
}

Link: DocumentRoot.java

about 4 years ago · Santiago Trujillo Denunciar

0

For Spring Boot 2.x+

@Component
public class EmbeddedServletContainerConfig implements WebServerFactoryCustomizer<TomcatServletWebServerFactory> {

    @Override
    public void customize(TomcatServletWebServerFactory factory) {
        factory.setDocumentRoot(new File("/your/path/here"));
    }

}
about 4 years ago · Santiago Trujillo Denunciar

0

I found a programmatically way of setting the docbase folder with spring and the embedded tomcat server. You must override the TomcatEmbeddedServletContainerFactory implementation like the following:

public @Bean EmbeddedServletContainerFactory embeddedServletContainerFactory() {
    TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory("/app", 8080) {
        @Override
        protected void configureContext(Context context, ServletContextInitializer[] initializers) {
            context.setDocBase("/path/to/your/docbase");
            super.configureContext(context, initializers);
        }
    };
    return factory;
}
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda