我是Google App Engine的新手 .
我一直在尝试将练习部署到Google Cloud .
这是项目,以防您想要详细查看配置:
这个项目是用Java 8和Spring Boot制作的 .
这是pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<!-- dependency versions -->
<com.google.guava.guava.version>21.0</com.google.guava.guava.version>
<io.springfox.springfox-swagger2>2.3.1</io.springfox.springfox-swagger2>
<io.springfox.springfox-swagger-ui>2.3.1</io.springfox.springfox-swagger-ui>
<commons-lang.version>3.0</commons-lang.version>
<junit.version>4.12</junit.version>
<jsonpath.version>2.2.0</jsonpath.version>
</properties>
<dependencies>
<!-- For default Spring Boot utilities -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<!-- For testing possibility -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- For all mvc and web functions -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<!-- Default persistence functions -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-java8</artifactId>
<version>5.0.5.Final</version>
</dependency>
<!-- In-Memory DB -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Java Utilities from google -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${com.google.guava.guava.version}</version>
</dependency>
<!-- Include swagger for API description -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${io.springfox.springfox-swagger2}</version>
</dependency>
<!-- Include swagger for API description UI -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${io.springfox.springfox-swagger-ui}</version>
</dependency>
<!-- Commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang.version}</version>
</dependency>
<!-- Unit testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>${jsonpath.version}</version>
<scope>test</scope>
</dependency>
<!-- Google cloud -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.7.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.3.2</version>
</plugin>
</plugins>
</build>
这是app.yaml
runtime: java
env: flex
runtime_config: # Optional
jdk: openjdk8
handlers:
- url: /.*
script: this field is required, but ignored
manual_scaling:
instances: 1
这是appengine-web.xml
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<version>1</version>
<threadsafe>true</threadsafe>
<runtime>java8</runtime>
</appengine-web-app>
我没有提供web.xml
我能够使用以下命令部署它:
mvn appengine:run
这是控制台ouptut . 我似乎已成功部署:
[INFO] GCLOUD: 2017-12-09 16:48:39.319:INFO::main: Logging initialized @501ms
[INFO] GCLOUD: 2017-12-09 16:48:39.867:INFO:oejs.Server:main: jetty-9.3.18.v20170406
[INFO] GCLOUD: 2017-12-09 16:48:45.673:INFO:oeja.AnnotationConfiguration:main: Scanning elapsed time=5286ms
[INFO] GCLOUD: Dec 09, 2017 7:48:45 PM com.google.appengine.tools.development.ApiProxyLocalImpl log
[INFO] GCLOUD: INFO: javax.servlet.ServletContext log: 1 Spring WebApplicationInitializers detected on classpath
[INFO] GCLOUD: 2017-12-09 16:48:46.541:INFO:oejsh.ContextHandler:main: Started c.g.a.t.d.j.DevAppEngineWebAppContext@7bd7d6d6{/,[file:///home/sebastiandagostino/mutant-api-exercise/target/mutant-exercise-1.0-SNAPS
HOT/, jar:file:///home/sebastiandagostino/mutant-api-exercise/target/mutant-exercise-1.0-SNAPSHOT/WEB-INF/lib/springfox-swagger-ui-2.3.1.jar!/META-INF/resources],AVAILABLE}{/home/sebastiandagostino/mutant-api-exer
cise/target/mutant-exercise-1.0-SNAPSHOT}
[INFO] GCLOUD: 2017-12-09 16:48:46.558:INFO:oejs.AbstractConnector:main: Started NetworkTrafficSelectChannelConnector@4722ef0c{HTTP/1.1,[http/1.1]}{localhost:8080}
[INFO] GCLOUD: 2017-12-09 16:48:46.561:INFO:oejs.Server:main: Started @7745ms
[INFO] GCLOUD: Dec 09, 2017 7:48:46 PM com.google.appengine.tools.development.AbstractModule startup
[INFO] GCLOUD: INFO: Module instance default is running at http://localhost:8080/
[INFO] GCLOUD: Dec 09, 2017 7:48:46 PM com.google.appengine.tools.development.AbstractModule startup
[INFO] GCLOUD: INFO: The admin console is running at http://localhost:8080/_ah/admin
[INFO] GCLOUD: Dec 09, 2017 4:48:46 PM com.google.appengine.tools.development.DevAppServerImpl doStart
[INFO] GCLOUD: INFO: Dev App Server is now running
当我尝试从预览中获取URL时,我得到 Error 403 .
然后我跑:
gcloud app deploy
为了使gcloud命令起作用,我将app.yaml复制到目标文件夹 .
我得到 404 Not Found . 我甚至检查了日志:
Waiting for new log entries...
2017-12-09 20:09:52 default[20171209t170858] "GET / HTTP/1.1" 404
2017-12-09 20:10:13 default[20171209t170858] "GET / HTTP/1.1" 404
2017-12-09 20:10:15 default[20171209t170858] "GET / HTTP/1.1" 404
2017-12-09 20:10:16 default[20171209t170858] "GET / HTTP/1.1" 404
2017-12-09 20:10:16 default[20171209t170858] "GET / HTTP/1.1" 404
2017-12-09 20:10:16 default[20171209t170858] "GET / HTTP/1.1" 404
2017-12-09 20:10:16 default[20171209t170858] "GET / HTTP/1.1" 404
2017-12-09 20:10:16 default[20171209t170858] "GET / HTTP/1.1" 404
2017-12-09 20:10:17 default[20171209t170858] "GET / HTTP/1.1" 404
2017-12-09 20:10:17 default[20171209t170858] "GET / HTTP/1.1" 404
2017-12-09 20:10:17 default[20171209t170858] "GET / HTTP/1.1" 404
2017-12-09 20:10:17 default[20171209t170858] "GET / HTTP/1.1" 404
2017-12-09 20:10:19 default[20171209t170858] "GET / HTTP/1.1" 404
2017-12-09 20:10:23 default[20171209t170858] "GET /swagger HTTP/1.1" 404
2017-12-09 20:10:38 default[20171209t170858] "GET / HTTP/1.1" 404
2017-12-09 20:10:44 default[20171209t170858] "GET / HTTP/1.1" 404
2017-12-09 20:11:22 default[20171209t170858] "GET / HTTP/1.1" 404
因此,应用程序编译和部署......但有些配置存在问题 . 我一直在寻找,仍然没有任何线索 .
Here表示我需要添加以下类:
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MutantApplication.class);
}
}
我这样做了,但它编译失败了:
[INFO] GCLOUD: 20:37:33.990 [main] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Replacing PropertySource 'servletContextInitParams' with 'servletContextInitParams'
[INFO] GCLOUD: 20:37:34.056 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
[INFO] GCLOUD: 20:37:34.057 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-starter/target/classes/, /spring-boot-autoconfigure/target/classes/, /spring-boot-starter-[\w-]+/, /spring-boot/target/classes/, /spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/]
[INFO] GCLOUD: 20:37:34.057 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : [file:/C:/Users/Sebastian/workspace/mutant-exercise/target/mutant-exercise-1.0-SNAPSHOT/WEB-INF/classes/]
[INFO] GCLOUD: java.lang.IllegalArgumentException: Unable to find the main class to restart
[INFO] GCLOUD: at org.springframework.util.Assert.notNull(Assert.java:134)
[INFO] GCLOUD: at org.springframework.boot.devtools.restart.Restarter.doStart(Restarter.java:285)
[INFO] GCLOUD: at org.springframework.boot.devtools.restart.Restarter.start(Restarter.java:273)
[INFO] GCLOUD: at org.springframework.boot.devtools.restart.Restarter$1.call(Restarter.java:174)
[INFO] GCLOUD: at org.springframework.boot.devtools.restart.Restarter$1.call(Restarter.java:170)
[INFO] GCLOUD: at org.springframework.boot.devtools.restart.Restarter$LeakSafeThread.run(Restarter.java:627)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 21.114 s
[INFO] Finished at: 2017-12-09T17:37:34-03:00
[INFO] Final Memory: 39M/263M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.google.cloud.tools:appengine-maven-plugin:1.3.2:run (default-cli) on project mutant-exercise: Execution default-cli of goal com.google.cloud.tools:appengine-maven-plugin:1.3.2:run failed: Non zero exit: 1 -> [Help 1]
真奇怪 . 它说它无法找到主类 .
1 回答
按照以下步骤将其部署在App Engine标准中:
克隆git repo https://github.com/sebastiandagostino/mutant-api-exercise.git
下载并安装适用于您操作系统的STS:https://spring.io/tools/sts/all
一旦安装并运行 . 单击“帮助 - > Eclipse Marketplace”并搜索Google Cloud插件 . 安装它 .
安装Google Cloud SDK(在我的情况下我使用了linux指令)https://cloud.google.com/sdk/downloads#interactive
安装 app-engine-java component ,参见here然后here
安装组件并在Google Cloud Platform中进行身份验证后 . 在Eclipse中,单击“窗口 - >首选项”,然后单击Google Cloud Tools(这些是Google Cloud插件的首选项) . 在SDK位置中,选择安装SDK的文件夹 . 见下图 .
现在您已准备好使用sts导入项目:
选择“new..project:Google App Engine Standard Project” .
点击下一步 . 取消选中“使用默认位置”,以便选择包含您下载的git项目的文件夹 .
导入后 . 右键单击项目名称,然后转到“configure - > Convert to maven project”
在maven解决所有导入后,再次右键单击项目名称并选择“Deploy to app engine standard” . 系统会打开一个窗口,您需要在该窗口中验证帐户并选择Google Cloud项目 .
部署完成后,你应该去https://your-project-id.appspot.com/