2017-07-24 2 views
0

Ich versuche, eine Feder-Anwendung auf Tomcat mit dem bmuschko tomcat-Plugin (https://github.com/bmuschko/gradle-tomcat-plugin) zu implementieren.Bereitstellen einer Spring-Anwendung mit Tomcat-Gradle-Plugin

Ich habe eine index.jsp in meinem Webapp-Ordner, der korrekt angezeigt wird. Die Sache ist, dass meine Anwendung nicht bereitgestellt wird. (aber Tomcat funktioniert einwandfrei, da meine index.jsp korrekt angezeigt wird). Ich denke, es könnte mit der Tatsache zusammenhängen, dass es eine Frühlingsanwendung ist, aber ich habe keine Ahnung, wie ich das überwinden kann (ich bekomme keinen Fehler und bin mir nicht sicher, wo ich meinen Katalog finden kann).

Meine Klasse build.gradle:

buildscript { 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.3.RELEASE") 
    } 
} 

apply plugin: 'java' 
apply plugin: 'eclipse' 
apply plugin: 'idea' 
apply plugin: 'spring-boot' 
apply plugin: 'war' 
apply plugin: 'com.bmuschko.tomcat' 

jar { 
    baseName = 'gs-accessing-data-jpa' 
    version = '0.1.0' 
    manifest { 
     attributes 'Main-Class': 'tutorialDatabaseServer.Application' 
    } 
} 

repositories { 
    mavenCentral() 
    maven { 
     url "https://repository.jboss.org/nexus/content/repositories/releases" 
    } 
} 

sourceCompatibility = 1.8 
targetCompatibility = 1.8 

dependencies { 
    compile("org.springframework.boot:spring-boot-starter-data-jpa") 
    compile("org.postgresql:postgresql") 
    testCompile("junit:junit") 

    compile("org.springframework.boot:spring-boot-starter-web") 
    compile("org.springframework.boot:spring-boot-starter-actuator") 
    // compile("org.postgresql:postgresql:9.4-1201-jdbc41") 
    compile("com.fasterxml.jackson.core:jackson-databind") 
    compile("org.liquibase:liquibase-core:3.3.3") 
    compile("org.springframework.boot:spring-boot-starter-data-mongodb") 
    compile 'org.springframework.boot:spring-boot-starter-thymeleaf' 
    compile("org.springframework.boot:spring-boot-starter-web") 
    compile group: 'org.hibernate', name: 'hibernate-validator', version:'4.2.0.Final' 
    compile group: 'javax.el', name: 'el-api', version: '2.2.1-b04' 
    compile group: 'org.postgresql', name: 'postgresql', version: '9.4.1212' 

    def tomcatVersion = '8.5.16' 
    tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}", 
     "org.apache.tomcat.embed:tomcat-embed-logging-juli:8.5.2", 
     "org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}" 

} 

tomcat { 
    httpProtocol = 'org.apache.coyote.http11.Http11Nio2Protocol' 
    ajpProtocol = 'org.apache.coyote.ajp.AjpNio2Protocol' 
} 


task wrapper(type: Wrapper) { 
    gradleVersion = '2.3' 
} 

buildscript { 

    repositories { 
     jcenter() 
    } 

    dependencies { 
     classpath 'com.bmuschko:gradle-tomcat-plugin:2.3' 
    } 
} 

und meine Anwendung:

@SpringBootApplication 
public class Application { 

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

public static void main(String[] args) { 
    SpringApplication.run(Application.class); 
} 
} 

Vielen Dank.

EDIT: nach meiner Anwendungsklasse, wie vorgeschlagen, der Kater log ändert, ist die folgende:

jul 25, 2017 8:53:37 AM org.apache.coyote.AbstractProtocol init 
INFORMACIÓN: Initializing ProtocolHandler ["http-nio2-8080"] 
jul 25, 2017 8:53:37 AM org.apache.coyote.AbstractProtocol init 
INFORMACIÓN: Initializing ProtocolHandler ["ajp-nio2-8009"] 
jul 25, 2017 8:53:37 AM org.apache.catalina.core.StandardService startInternal 
INFORMACIÓN: Starting service [Tomcat] 
jul 25, 2017 8:53:37 AM org.apache.catalina.core.StandardEngine startInternal 
INFORMACIÓN: Starting Servlet Engine: Apache Tomcat/8.5.16 
jul 25, 2017 8:53:37 AM org.apache.catalina.startup.ContextConfig getDefaultWebXmlFragment 
INFORMACIÓN: No global web.xml found 
jul 25, 2017 8:54:08 AM org.apache.jasper.servlet.TldScanner scanJars 
INFORMACIÓN: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 
jul 25, 2017 8:54:09 AM org.apache.jasper.servlet.TldScanner scanJars 
INFORMACIÓN: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 
jul 25, 2017 8:54:09 AM org.apache.catalina.core.ApplicationContext log 
INFORMACIÓN: Spring WebApplicationInitializers detected on classpath: [org.springframework.boot.autoconfigure[email protected]1f014eaa] 
jul 25, 2017 8:54:09 AM org.apache.coyote.AbstractProtocol start 
INFORMACIÓN: Starting ProtocolHandler ["http-nio2-8080"] 
jul 25, 2017 8:54:09 AM org.apache.coyote.AbstractProtocol start 
INFORMACIÓN: Starting ProtocolHandler ["ajp-nio2-8009"] 
jul 25, 2017 8:55:31 AM org.apache.coyote.AbstractProtocol init 
INFORMACIÓN: Initializing ProtocolHandler ["http-nio2-8080"] 
jul 25, 2017 8:55:31 AM org.apache.coyote.AbstractProtocol init 
INFORMACIÓN: Initializing ProtocolHandler ["ajp-nio2-8009"] 
jul 25, 2017 8:55:31 AM org.apache.catalina.core.StandardService startInternal 
INFORMACIÓN: Starting service [Tomcat] 
jul 25, 2017 8:55:31 AM org.apache.catalina.core.StandardEngine startInternal 
INFORMACIÓN: Starting Servlet Engine: Apache Tomcat/8.5.16 
jul 25, 2017 8:55:31 AM org.apache.catalina.startup.ContextConfig getDefaultWebXmlFragment 
INFORMACIÓN: No global web.xml found 
jul 25, 2017 8:56:02 AM org.apache.jasper.servlet.TldScanner scanJars 
INFORMACIÓN: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 
jul 25, 2017 8:56:03 AM org.apache.jasper.servlet.TldScanner scanJars 
INFORMACIÓN: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 
jul 25, 2017 8:56:03 AM org.apache.catalina.core.ApplicationContext log 
INFORMACIÓN: Spring WebApplicationInitializers detected on classpath: [org.springframework.boot.autoconfigure[email protected]4988a907, [email protected]] 

Antwort

1

Sie müssen SpringBootServletInitializer erweitern und außer Kraft setzen configure() -Methode als Kriegs-Datei bereitstellen, finden Sie spring boot docs.

@SpringBootApplication 
public class Application extends SpringBootServletInitializer { 

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

    public static void main(String[] args) { 
     SpringApplication.run(Application.class); 
    } 

    @Override 
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { 
     return builder.sources(Application.class); 
    } 

} 

Edit:

Ihre build.gradle enthält inkompatible Protokollierung Abhängigkeiten. Beim Start lädt der Classloader keine slf4j-Klassen und wird mit java.lang.StackOverflowError beendet. Um es zu lösen, musste ich Build.gradle wie unten ändern.

buildscript { 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.4.RELEASE") 
     classpath 'com.bmuschko:gradle-tomcat-plugin:2.3' 
    } 
} 

apply plugin: 'java' 
apply plugin: 'eclipse' 
apply plugin: 'idea' 
apply plugin: 'spring-boot' 
apply plugin: 'war' 
apply plugin: 'com.bmuschko.tomcat' 

jar { 
    baseName = 'gs-accessing-data-jpa' 
    version = '0.1.0' 
    manifest { 
     attributes 'Main-Class': 'tutorialDatabaseServer.Application' 
    } 
} 

repositories { 
    mavenCentral() 
    maven { 
     url "https://repository.jboss.org/nexus/content/repositories/releases" 
    } 
} 

sourceCompatibility = 1.8 
targetCompatibility = 1.8 

dependencies { 
    compile('ch.qos.logback:logback-classic:1.2.3') 
    compile('org.slf4j:jcl-over-slf4j:1.7.25') 

    compile('org.springframework.boot:spring-boot-starter-web') { 
     exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' 
    } 

    compile("org.springframework.boot:spring-boot-starter-data-jpa") { 
     exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' 
    } 

    compile("org.springframework.boot:spring-boot-starter-actuator") { 
     exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' 
    } 

    compile('org.springframework.boot:spring-boot-starter-thymeleaf') { 
     exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' 
    } 

    compile("com.fasterxml.jackson.core:jackson-databind") 
    compile("org.liquibase:liquibase-core:3.3.3") 
    compile('javax.el:el-api:2.2.1-b04') 
    compile('org.postgresql:postgresql:9.4.1212') 

    testCompile("junit:junit") 

    def tomcatVersion = '8.5.15' 
    tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}", 
      "org.apache.tomcat.embed:tomcat-embed-logging-juli:8.5.2", 
      "org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}" 
    } 

    tomcat { 
     httpProtocol = 'org.apache.coyote.http11.Http11Nio2Protocol' 
     ajpProtocol = 'org.apache.coyote.ajp.AjpNio2Protocol' 
    } 

    task wrapper(type: Wrapper) { 
     gradleVersion = '2.3' 
    } 
+0

jetzt bekomme ich den Fehler: FAILURE: Build mit einer Ausnahme fehlgeschlagen. * Was schief gelaufen ist: Ausführung fehlgeschlagen für Task ': tomcatRun'. > java.lang.StackOverflowError (keine Fehlermeldung) * Versuchen: Mit --stacktrace Option ausführen, um die Stack-Trace zu erhalten. Führen Sie die Option --info oder --debug aus, um mehr Protokollausgaben zu erhalten. @taner –

+0

Können Sie outputFile des Plugins festlegen, um zu sehen, was in Tomcat-Protokollen gedruckt wird. – taner

+0

Ich habe den Tomcat-Log @taner hinzugefügt. Danke nochmal –

Verwandte Themen