4

I have a Spring MVC webapp in Eclipse, which I build with Gradle. I'm using the Gradle Tomcat plugin as well.

When I run the Gradle tomcatRunWar task, everything works as expected and my webapp is responsive, as it should be. But when I run the Gradle tomcatRun task, although it appears to be successful and says "server is running at http://localhost:8080/", the webapp only throws 404 errors with the message "The requested resource is not available".

I then ran the Gradle task with the -i (info) and -d (debug) options and I see the following when I try to hit the server:

17:28:43.030 [DEBUG] [org.apache.tomcat.util.threads.LimitLatch] Counting up[http-bio-8080-Acceptor-0] latch=1
17:28:43.031 [DEBUG] [org.apache.catalina.connector.CoyoteAdapter] The variable [uriBC] has value [/]
17:28:43.031 [DEBUG] [org.apache.catalina.connector.CoyoteAdapter] The variable [semicolon] has value [-1]
17:28:43.031 [DEBUG] [org.apache.catalina.connector.CoyoteAdapter] The variable [enc] has value [UTF-8]
17:28:43.032 [DEBUG] [org.apache.catalina.authenticator.AuthenticatorBase] Security checking request GET /
17:28:43.032 [DEBUG] [org.apache.catalina.realm.RealmBase]   No applicable constraints defined
17:28:43.032 [DEBUG] [org.apache.catalina.authenticator.AuthenticatorBase]  Not subject to any constraint
17:28:43.032 [DEBUG] [org.apache.coyote.http11.Http11Protocol] Socket: [org.apache.tomcat.util.net.SocketWrapper@5a2e857e:Socket[addr=/0:0:0:0:0:0:0:1,port=52381,localport=8080]], Status in: [OPEN_READ], State out: [OPEN]
17:28:45.216 [DEBUG] [org.apache.catalina.loader.WebappClassLoader] modified()
17:28:45.216 [DEBUG] [org.apache.catalina.loader.WebappClassLoader]     Failed tracking modifications of '/WEB-INF/lib'
17:29:05.220 [DEBUG] [org.apache.catalina.session.ManagerBase] Start expire sessions StandardManager at 1423099745220 sessioncount 0
17:29:05.220 [DEBUG] [org.apache.catalina.session.ManagerBase] End expire sessions StandardManager processingTime 0 expired sessions: 0

If I wait another 10 seconds or so, I then see this:

17:29:35.224 [DEBUG] [org.apache.catalina.loader.WebappClassLoader] modified()
17:29:35.225 [DEBUG] [org.apache.catalina.loader.WebappClassLoader]     Failed tracking modifications of '/WEB-INF/lib'
17:29:43.033 [DEBUG] [org.apache.coyote.http11.Http11Processor] Error parsing HTTP request header
java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:150)
    at java.net.SocketInputStream.read(SocketInputStream.java:121)
    at org.apache.coyote.http11.InternalInputBuffer.fill(InternalInputBuffer.java:519)
    at org.apache.coyote.http11.InternalInputBuffer.fill(InternalInputBuffer.java:504)
    at org.apache.coyote.http11.Http11Processor.setRequestLineReadTimeout(Http11Processor.java:167)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:982)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
17:29:43.033 [DEBUG] [org.apache.coyote.http11.Http11Protocol] Socket: [org.apache.tomcat.util.net.SocketWrapper@5a2e857e:Socket[addr=/0:0:0:0:0:0:0:1,port=52381,localport=8080]], Status in: [OPEN_READ], State out: [CLOSED]
17:29:43.034 [DEBUG] [org.apache.tomcat.util.threads.LimitLatch] Counting down[http-bio-8080-exec-9] latch=1
17:29:45.225 [DEBUG] [org.apache.catalina.loader.WebappClassLoader] modified()

I am perplexed and would appreciate your help! My build.gradle is included below.

apply plugin: 'war'
apply plugin: 'com.bmuschko.tomcat'
apply plugin: 'java'
apply plugin: 'propdeps'
apply plugin: 'propdeps-maven'
apply plugin: 'propdeps-idea'
apply plugin: 'propdeps-eclipse'
apply plugin: 'eclipse'
apply plugin: 'idea'

buildscript {
  repositories {
    mavenCentral()
    maven { url "http://download.java.net/maven/2" }
    maven { url 'http://repo.spring.io/plugins-release' }

    jcenter()
  }

  dependencies {
    // classpath 'org.gradle.api.plugins:gradle-tomcat-plugin:2.0'
    classpath 'org.springframework.build.gradle:propdeps-plugin:0.0.7'
    classpath 'com.bmuschko:gradle-tomcat-plugin:2.0'
  }
}

repositories {
  mavenCentral()
  maven { url 'http://repo.spring.io/milestone/'}
}

dependencies {

    compile fileTree(dir: 'lib', include: '*.jar')

    def tomcatVersion = '7.0.57'
    tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
            "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}"
    tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") {
      exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
    }

    compile 'org.codemonkey.simplejavamail:simple-java-mail:2.1'

    compile 'org.springframework:spring-core:4.1.4.RELEASE'
    compile 'org.springframework:spring-webmvc:4.1.4.RELEASE'
    compile 'com.jayway.jsonpath:json-path:0.8.1'

    // {!begin hateoas}
    compile 'org.springframework.hateoas:spring-hateoas:0.16.0.RELEASE'
    // {!end hateoas}

    compile 'org.springframework.security:spring-security-web:3.2.5.RELEASE'
    compile 'org.springframework.security:spring-security-core:3.2.5.RELEASE'
    compile 'org.springframework.security:spring-security-config:3.2.5.RELEASE'

    compile 'org.slf4j:slf4j-api:1.7.5'
    //runtime 'org.slf4j:slf4j-jdk14:1.7.5'
    runtime 'org.slf4j:slf4j-log4j12:1.7.5'
    //compile 'log4j:log4j:1.2.16'

    runtime 'com.fasterxml.jackson.core:jackson-core:2.2.2'
    runtime 'com.fasterxml.jackson.core:jackson-databind:2.2.2'
    runtime 'javax.xml.bind:jaxb-api:2.2.9'

    // providedCompile 'javax.servlet:javax.servlet-api:3.0.1'
    providedCompile 'javax.servlet:javax.servlet-api:3.1.0'


    testCompile 'com.jayway.jsonpath:json-path-assert:0.8.1'
    testCompile 'org.springframework:spring-test:3.2.3.RELEASE'
    testCompile 'junit:junit:4.+'
    testCompile "org.mockito:mockito-all:1.9.5"

    compile 'org.springframework:spring-jdbc:4.1.4.RELEASE'
    compile 'mysql:mysql-connector-java:5.1.26'

    compile 'com.google.guava:guava:16.0.1' 
}

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

tomcatRunWar.contextPath = ''
tomcatRun.contextPath = ''

tomcatRun.outputFile = file('tomcatRunLog.txt')
tomcatRunWar.outputFile = file('tomcatRunWarLog.txt')
AlexG
  • 1,596
  • 2
  • 17
  • 26

3 Answers3

0

Your project layout needs to have at least src/main/webapp/WEB-INF/web.xml even if you declare another web.xml with tomcatRun.webDefaultXml.

skolem
  • 151
  • 3
0

Maybe you should remove tomcatRunWar.contextPath. I'm not sure if '' is deployed as the ROOT context. The 404 indicates, that the war is not deployed into the ROOT context. If you remove the contextPath you should be able to call http://localhost:8080/

Jens
  • 241
  • 2
  • 9
0

We need to add Web Content folder in Deployment Assembly as Gradle doesn't configure it by default.