我正在Google Cloud Platform中部署Spring Boot Rest API。在将应用程序作为Spring Boot应用程序运行时,Rest API在我的本地环境中运行良好。但是,在GCP中进行部署时,无法识别相同的REST API URL。
app.yaml:
this should be displayed
this too
and this
GreetingController.java
runtime: java
env: flex
runtime_config:
jdk: openjdk8
handlers:
- url: /.*
script: this field is required, but ignored
Application.java
package com.designdreamers.rest.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.designdreamers.rest.vo.Greeting;
@RestController
public class GreetingController {
private int idValue;
@RequestMapping(value="/greet")
public Greeting greeting(@RequestParam(value="content", defaultValue = "Hello World!!")String content){
Greeting greeting=new Greeting();
greeting.setId(idValue++);
greeting.setContent(content);
return greeting;
}
}
下面是我在本地作为Spring Boot应用程序运行应用程序时得到的REST API响应。
URL: http://localhost:8080/greet
package com.designdreamers.rest.main;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan(basePackages = "com.designdreamers.rest.controller")
public class Application {
public static void main(String args[]){
SpringApplication.run(Application.class,args);
}
}
我在GCP中部署了相同的应用程序,并点击了REST API URI,以下是我们得到的错误。
URI: http://helloworld-001.appspot.com/greet
{"id":1,"content":"Hello World!!"}
帮助确定问题将非常有帮助。