Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google AppEngine Standard Local Server (Java8) + Spring Boot + WebFlux doesn't see my @RestController

I'm trying to launch HelloWorld applications on

  • Google AppEngine Standard Local Server (Java 8)
  • Spring Boot 2.0.0.M5 (Spring 5)
  • Spring WebFlux (Reactive web controller)
  • Gradle

It works perfectly if I run it as a Spring Boot application but ComponentScan doesn't see my @RestController bean.

I use ServletInitializer and I can from console output and in Intellij IDEA debug mode that it enters into it. Spring sees the application bean but not the controller.

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

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

}

So I have empty 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 Spring Boot Application class sits in the root of the package hierarchy, so all @Components expectedly have to be found by Spring component scanner.

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

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

This is the 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 output of 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.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
like image 936
4ilin Avatar asked Nov 03 '17 18:11

4ilin


1 Answers

Spring Boot does not support WAR deployment with Spring WebFlux.

like image 87
Brian Clozel Avatar answered Nov 15 '22 03:11

Brian Clozel