gpt4 book ai didi

java - WebServlet 注释正在使用,但 GAE 正在尝试查找 web.xml

转载 作者:行者123 更新时间:2023-11-30 06:14:24 27 4
gpt4 key购买 nike

据我所知,如果我使用 WebServlet 注释,我应该不需要 web.xml。我正在尝试使用 gradle 的 Google App Engine Standard 本地服务器,但尝试查找 web.xml 失败。

C:\Projects\x\x\Research\testeng>gradle appengineRun
Mar 28, 2018 1:17:18 PM java.util.prefs.WindowsPreferences
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
Mar 28, 2018 1:17:18 PM com.google.apphosting.utils.config.AbstractConfigXmlReader readConfigXml
SEVERE: Received exception processing C:\Projects\x\x\Research\testeng\build\exploded-testeng\WEB-INF\web.xml
com.google.apphosting.utils.config.AppEngineConfigException: Could not locate C:\Projects\x\x\Research\testeng\build\exploded-testeng\WEB-INF\web.xml

我做错了什么......?

我得到了 servlet 的 stub

@WebServlet("/TestServlet")
public class TestServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}

我的 build.gradle 非常接近 Using Gradle and the App Engine Plugin 中使用的内容:

buildscript {    // Configuration for building
repositories {
jcenter() // Bintray's repository - a fast Maven Central mirror & more
mavenCentral()
}
dependencies {
classpath 'com.google.cloud.tools:appengine-gradle-plugin:+' // latest App Engine Gradle tasks
}
}

repositories { // repositories for Jar's you access in your code
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots' // SNAPSHOT repository (if needed)
}
mavenCentral()
jcenter()
}

apply plugin: 'java' // standard Java tasks
apply plugin: 'war' // standard Web Archive plugin
apply plugin: 'com.google.cloud.tools.appengine' // App Engine tasks

sourceSets {
// main.kotlin.srcDirs += "src/main/kotlin"
main.java.srcDirs += "src/main/java"
}

dependencies {
compile 'com.google.appengine:appengine-api-1.0-sdk:+' // Latest App Engine Api's
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'

compile 'jstl:jstl:1.2'

// Add your dependencies here.
// compile 'com.google.cloud:google-cloud:+' // Latest Cloud API's http://googlecloudplatform.github.io/google-cloud-java

testCompile 'junit:junit:4.12'
testCompile 'com.google.truth:truth:0.33'
testCompile 'org.mockito:mockito-all:1.10.19'

testCompile 'com.google.appengine:appengine-testing:+'
testCompile 'com.google.appengine:appengine-api-stubs:+'
testCompile 'com.google.appengine:appengine-tools-sdk:+'
}

// Always run unit tests
appengineDeploy.dependsOn test
appengineStage.dependsOn test

appengine { // App Engine tasks configuration
deploy { // deploy configuration

}
}

test {
useJUnit()
testLogging.showStandardStreams = true
beforeTest { descriptor ->
logger.lifecycle("test: " + descriptor + " Running")
}

onOutput { descriptor, event ->
logger.lifecycle("test: " + descriptor + ": " + event.message )
}
afterTest { descriptor, result ->
logger.lifecycle("test: " + descriptor + ": " + result )
}
}

group = "com.testeng" // Generated output GroupId
version = "1.0-SNAPSHOT" // Version in generated output

sourceCompatibility = 1.8 // App Engine Flexible uses Java 8
targetCompatibility = 1.8 // App Engine Flexible uses Java 8

最佳答案

您需要 web.xmlappengine-web.xml如果您在 Java 中使用 GAE 标准,因为它们用于描述您的应用程序的配置方式。

您可以查看文档,详细了解您的应用程序所需的配置设置。

关于java - WebServlet 注释正在使用,但 GAE 正在尝试查找 web.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49541748/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com