gpt4 book ai didi

spring - Google AppEngine 标准本地服务器 (Java8) + Spring Boot + WebFlux 没有看到我的@RestController

转载 作者:太空宇宙 更新时间:2023-11-03 15:25:24 24 4
gpt4 key购买 nike

我正在尝试启动 HelloWorld 应用程序

  • Google AppEngine 标准本地服务器 (Java 8)
  • Spring Boot 2.0.0.M5( Spring 5)
  • Spring WebFlux(响应式网络 Controller )
  • Gradle

如果我将它作为 Spring Boot 应用程序运行但 ComponentScan 看不到我的 @RestController bean,它会完美运行。

我使用 ServletInitializer,我可以从控制台输出和它进入的 Intellij IDEA Debug模式。 Spring 看到应用程序 bean 但看不到 Controller 。

package test.gcp.hello;
...
public class ServletInitializer extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(DtmsApiGcpApplication.class);
}

}

所以我有空的src/main/webapp/WEB-INF/web.xml:

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
</web-app>

最小 src/main/webapp/WEB-INF/appengine-web.xml:

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<version>0.0.1</version>
<threadsafe>true</threadsafe>
<runtime>java8</runtime>
</appengine-web-app>

我的 Spring Boot Application 类位于包层次结构的根部,因此所有 @Components 都必须由 Spring 组件扫描器找到。

package test.gcp.hello;
...
@SpringBootApplication
public class DtmsApiGcpApplication {

public static void main(String[] args) {
System.out.println("#######");
SpringApplication.run(DtmsApiGcpApplication.class, args);
}
}

这是 Controller :

package test.gcp.hello.controllers;
...
@RestController
public class NodeController {
@GetMapping(value = "/api/node", produces = "application/json;charset=UTF-8")
public Mono<Node> home() {
return Mono.just(new Node("alias", "The Alias Node"));
}
}

build.gradle:

buildscript {
ext {
springBootVersion = '2.0.0.M5'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath 'com.google.cloud.tools:appengine-gradle-plugin:+'
}
}

apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
apply plugin: "com.google.cloud.tools.appengine-standard"


group = 'eu.datatile.dtms.gcp'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}

configurations {
providedRuntime
}

dependencies {
compile('org.springframework.boot:spring-boot-starter-webflux')
providedCompile 'com.google.appengine:appengine:+'
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
testCompile('org.springframework.boot:spring-boot-starter-test')
}

appengine {

tools {
cloudSdkHome = "path/to/google-cloud-sdk"
}

run {
port = 8080
}

deploy {
stopPreviousVersion = true
promote = true
}
}

Google App Engine 标准本地服务器 的控制台输出:

Starting the App Engine local development server...
2017-11-03 19:35:24.932:INFO::main: Logging initialized @567ms
Connected to server
Nov 03, 2017 5:35:25 PM com.google.appengine.tools.development.IsolatedAppClassLoader checkWorkingDirectory
WARNING: Your working directory, (/Applications/IntelliJ IDEA.app/Contents/bin) is not equal to your
web application root (/Users/abc/dev/src/dtms/gcp/dtms-api-gcp/build/libs/exploded/dtms-api-gcp-0.0.1-SNAPSHOT.war)
You will not be able to access files from your working directory on the production server.

2017-11-03 19:35:25.291:INFO:oejs.Server:main: jetty-9.3.18.v20170406
2017-11-03 19:35:26.042:INFO:oeja.AnnotationConfiguration:main: Scanning elapsed time=540ms
Nov 03, 2017 5:35:26 PM com.google.appengine.tools.development.ApiProxyLocalImpl log
INFO: javax.servlet.ServletContext log: 2 Spring WebApplicationInitializers detected on classpath

...
17:35:26.171 [main] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Replacing PropertySource 'servletContextInitParams' with 'servletContextInitParams'

. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.0.M5)

2017-11-03 17:35:26.649 INFO 10294 --- [ main] e.d.dtms.gcp.api.ServletInitializer : Starting ServletInitializer on alexanders-mbp with PID 10294 (/Users/abc/dev/src/dtms/gcp/dtms-api-gcp/build/libs/exploded/dtms-api-gcp-0.0.1-SNAPSHOT.war/WEB-INF/classes started by abc in /Applications/IntelliJ IDEA.app/Contents/bin)
2017-11-03 17:35:26.650 INFO 10294 --- [ main] e.d.dtms.gcp.api.ServletInitializer : No active profile set, falling back to default profiles: default
2017-11-03 17:35:26.711 INFO 10294 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@573906eb: startup date [Fri Nov 03 17:35:26 UTC 2017]; root of context hierarchy
2017-11-03 17:35:27.316 INFO 10294 --- [ main] c.g.a.t.development.ApiProxyLocalImpl : javax.servlet.ServletContext log: Initializing Spring embedded WebApplicationContext
2017-11-03 17:35:27.316 INFO 10294 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 605 ms
2017-11-03 17:35:27.499 INFO 10294 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'errorPageFilter' to: [/*]
2017-11-03 17:35:27.499 INFO 10294 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-11-03 17:35:27.826 INFO 10294 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-11-03 17:35:27.838 INFO 10294 --- [ main] e.d.dtms.gcp.api.ServletInitializer : Started ServletInitializer in 1.658 seconds (JVM running for 3.474)
2017-11-03 19:35:28.005:INFO:oejsh.ContextHandler:main: Started c.g.a.t.d.j.DevAppEngineWebAppContext@6dfcffb5{/,file:///Users/abc/dev/src/dtms/gcp/dtms-api-gcp/build/libs/exploded/dtms-api-gcp-0.0.1-SNAPSHOT.war/,AVAILABLE}{/Users/abc/dev/src/dtms/gcp/dtms-api-gcp/build/libs/exploded/dtms-api-gcp-0.0.1-SNAPSHOT.war}
...
c.g.a.t.development.DevAppServerImpl : Dev App Server is now running

最佳答案

Spring Boot 不支持使用 Spring WebFlux 进行 WAR 部署。

关于spring - Google AppEngine 标准本地服务器 (Java8) + Spring Boot + WebFlux 没有看到我的@RestController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47102087/

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