2017-07-24 150 views
0

我試圖在tomcat上使用bmuschko tomcat插件(https://github.com/bmuschko/gradle-tomcat-plugin)部署spring應用程序。使用Tomcat gradle插件部署Spring應用程序

我的webapp文件夾中有一個index.jsp顯示正確。問題是我的應用程序沒有被部署。 (但Tomcat工作正常,因爲我的index.jsp顯示正確)。我認爲這可能與它是一個春季應用程序有關,但我不知道如何克服這個問題(我沒有得到任何錯誤,我不確定在哪裏可以找到我的卡塔利娜日誌)。

我班的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' 
    } 
} 

和我的應用程序:

@SpringBootApplication 
public class Application { 

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

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

非常感謝。

編輯:改變的建議我的應用程序類後,tomcat的日誌是下列之一:

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]] 

回答

1

您需要延長SpringBootServletInitializer並重寫configure()方法將其部署爲WAR文件,請參閱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); 
    } 

} 

編輯:

你的build.gradle包括不兼容的日誌依賴。在啓動時,類加載器無法加載slf4j類並使用java.lang.StackOverflowError退出。爲了解決它,我不得不像下面那樣修改build.gradle。

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

現在我得到錯誤:失敗:生成失敗,出現異常。 *發生了什麼問題: 任務':tomcatRun'的執行失敗。 > java.lang.StackOverflowError(無錯誤消息) *嘗試: 使用--stacktrace選項運行以獲取堆棧跟蹤。使用--info或--debug選項運行以獲取更多日誌輸出。 @taner –

+0

你能設置outputFile的插件來查看tomcat日誌中打印的內容嗎? – taner

+0

我已經添加了tomcat日誌@taner。再次感謝 –

相關問題