Home > database >  failed to initialize Tomcat while running Spring boot app with vaadin in docker
failed to initialize Tomcat while running Spring boot app with vaadin in docker

Time:12-12

I'm hobbyst and recently switched from heroku to render.com. I wanted to put my SringBoot app there but it requires me to run it in docker environment which I have no expirience with. I managed to write Dockerfile for it, and run it from jar file, but I still getting the log:

Caused by: java.lang.IllegalStateException: StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[] failed to start
Dec 11 12:57:44 PM      at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.rethrowDeferredStartupExceptions(TomcatWebServer.java:171) ~[spring-boot-2.2.4.RELEASE.jar!/:2.2.4.RELEASE]
Dec 11 12:57:44 PM      at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:110) ~[spring-boot-2.2.4.RELEASE.jar!/:2.2.4.RELEASE]  

My suspicion is that is becuse of vaadin-dev-server-settings.json:

{
  "frontendFolder": "C:/Users/kiemoon/IdeaProjects/Vadin/assistant_vaadin/frontend",
  "themeFolder": "themes",
  "themeResourceFolder": "C:/Users/kiemoon/IdeaProjects/Vadin/assistant_vaadin/build/flow-frontend",
  "staticOutput": "build/classes/META-INF/VAADIN/webapp/VAADIN/static",
  "generatedFolder": "generated",
  "frontendBundleOutput": "build/classes/META-INF/VAADIN/webapp/",
  "addonFrontendFolder": "build/flow-frontend/",
  "themeName": "",
  "clientServiceWorkerSource": "C:\\Users\\kiemoon\\IdeaProjects\\Vadin\\assistant_vaadin\\build\\sw.ts",
  "pwaEnabled": false,
  "offlineEnabled": false,
  "offlinePath": "'offline.html'"
}

or is it because of Dockerfile? :

FROM openjdk:11
WORKDIR /
ADD build/libs/assistant_vaadin-0.0.1-SNAPSHOT.jar app.jar
CMD java -jar -Dspring.profiles.active=prod app.jar

application.properties:

server.tomcat.accesslog.enabled=true

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true

spring.datasource.url=jdbc:*******
spring.datasource.username=*******
spring.datasource.password=*******
spring.datasource.driver-class-name=org.postgresql.Driver

vaadin.productionMode=true

buil.gradle:

buildscript {
    repositories {
        mavenCentral()
        maven { setUrl("https://maven.vaadin.com/vaadin-prereleases") }
        maven { setUrl("https://maven.vaadin.com/vaadin-addons") }
    }
}
plugins {
    id 'org.springframework.boot' version '2.2.4.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id 'java'
    id 'com.vaadin'
}

defaultTasks("clean", "build")

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
    maven { setUrl("https://maven.vaadin.com/vaadin-prereleases") }
    maven { setUrl("https://maven.vaadin.com/vaadin-addons") }
}

configurations {
    developmentOnly
    runtimeClasspath {
        extendsFrom developmentOnly
    }
}

dependencies {
    implementation('com.vaadin:vaadin-spring-boot-starter')
    implementation 'org.jetbrains:annotations:20.1.0'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    implementation 'com.opencsv:opencsv:5.7.1'
    implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    compileOnly 'org.projectlombok:lombok'
    runtimeOnly 'org.postgresql:postgresql:42.5.1'

    annotationProcessor 'org.projectlombok:lombok'
    implementation 'org.springframework.boot:spring-boot-starter'
}

dependencyManagement {
    imports {
        mavenBom "com.vaadin:vaadin-bom:$vaadinVersion"
    }
}

test {
    useJUnitPlatform()
}

// The following pnpmEnable = true is not needed as pnpm is used by default,
// this is just an example of how to configure the Gradle Vaadin Plugin:
// for more configuration options please see: https://vaadin.com/docs/latest/guide/start/gradle/#all-options
vaadin {
    pnpmEnable = true
}

bootRun {
    systemProperties = System.properties
}

CodePudding user response:

You need to enable production mode for the Gradle build and not only in the Spring configuration by setting productionMode = true in the vaadin section of build.gradle or by running Gradle with -Pvaadin.productionMode=true.

See https://vaadin.com/docs/latest/guide/start/gradle/#production for more information, but note that the very first examples assume a war deployment rather than using Spring Boot.

  • Related