我在Eclipse中有一个Spring MVC Web应用程序,它是我用Gradle构建的。我也在使用Gradle Tomcat插件。
当我运行GradletomcatRunWar任务时,一切都按预期进行,我的网络应用程序也会做出响应。但当我运行GradletomcatRun时,尽管它看起来很成功,并显示"服务器正在http://localhost:8080/,Web应用程序只抛出404个错误,并显示消息"请求的资源不可用"。
然后,我用-I(info)和-d(debug)选项运行Gradle任务,当我尝试访问服务器时,我看到以下内容:
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
如果我再等10秒左右,我就会看到:
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()
我很困惑,非常感谢你的帮助!我的build.gradle包含在下面。
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')
即使您使用tomcatRun.webDefaultXml.
也许你应该删除tomcatRunWar.contextPath。我不确定"是否被部署为ROOT上下文。404表示战争没有部署到ROOT上下文中。如果您删除了contextPath,您应该能够调用http://localhost:8080/
我们需要在部署程序集中添加Web内容文件夹,因为Gradle默认情况下不会配置它。