2017-11-03 4 views
3

Ich versuche Hello World Anwendungen starten aufGoogle App Engine-Standard Local Server (Java8) + Frühling Stiefel + WebFlux sieht nicht mein @RestController

  • Google App Engine-Standard Local Server (Java 8)
  • Frühlings-Boot-2.0.0.M5 (Feder 5)
  • Feder WebFlux (Reactive Web-Controller)
  • Gradle

Es funktioniert perfekt, wenn ich ru n es als Spring Boot-Anwendung, aber ComponentScan sieht meine @RestController Bean nicht.

Ich benutze ServletInitializer und ich kann von der Konsole Ausgabe und Intellij IDEA Debug-Modus, dass es in es eingeht. Spring sieht die Anwendung Bean, aber nicht den Controller.

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

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

} 

So habe ich leer 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> 

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

My Frühlings-Boot-Application-Klasse sitzt in der Wurzel der Pakethierarchie, so dass alle @Components expectedly müssen von Spring Komponentenscanner gefunden werden.

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

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

Dies ist der 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 
    } 
} 

Console Ausgabe von Google App Engine Standard Local Server:

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.ser[email protected]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 [email protected]{/,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 

Antwort

2

Frühlings-Boot nicht WAR-Bereitstellung unterstützt mit Frühling WebFlux.

+0

Danke, Brian. Es ist also unmöglich Spring WebFlux Server in AppEngine SE zu implementieren, richtig? – 4ilin

+1

Sie können mit Spring Framework. Dieser Anwendungsfall wird derzeit nicht von Spring Boot unterstützt. –

Verwandte Themen