简体   繁体   English

部署后无法访问Google App Engine中的Spring Boot应用程序

[英]Unable to access Spring Boot application in Google App Engine after deployment

I am new to Google App Engine. 我是Google App Engine的新手。

I have been trying to deploy an exercise to Google Cloud. 我一直在尝试将练习部署到Google Cloud。

This is the project in case you want to see the configuration in detail: 如果您想详细查看配置,这是项目:

Exercise Project to Deploy 练习项目以进行部署

This project is made with Java 8 and Spring Boot. 该项目是使用Java 8和Spring Boot创建的。

This is the pom.xml 这是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>

This is the app.yaml 这是app.yaml

runtime: java
env: flex

runtime_config:  # Optional
  jdk: openjdk8

handlers:
- url: /.*
  script: this field is required, but ignored

manual_scaling:
  instances: 1

This is the appengine-web.xml 这是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>

I did not provide a web.xml 我没有提供web.xml

I was able to deploy this with the command: 我能够使用以下命令部署它:

mvn appengine:run

This is the console ouptut. 这是控制台输出。 I seems to have deployed successfully: 我似乎已成功部署:

[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

When I try to reach the URL from the preview, I get Error 403 . 当我尝试从预览中访问URL时,出现错误403

Then I run: 然后我运行:

gcloud app deploy

In order to make that gcloud command to work, I copied the app.yaml to the target folder. 为了使该gcloud命令起作用,我将app.yaml复制到了目标文件夹。

I get 404 Not Found . 我得到404 Not Found I even checked the logs: 我什至查看了日志:

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

So, the app compiles and deploys... but somewhat there is some configuration problem. 因此,该应用程序可以编译和部署...但是在某种程度上存在一些配置问题。 I have been looking and still have no clue. 我一直在寻找,仍然没有任何线索。

Here states that I need to add the following class: 这里说明我需要添加以下类:

public class ServletInitializer extends SpringBootServletInitializer {

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

}

I did that, but it fails compiling then: 我做到了,但随后编译失败:

[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]

It is weird. 真奇怪。 It says that it can't find the main class. 它说找不到主类。

Deploy it in App Engine standard following these steps: 请按照以下步骤在App Engine标准中部署它:

Clone the git repo https://github.com/sebastiandagostino/mutant-api-exercise.git 克隆git仓库https://github.com/sebastiandagostino/mutant-api-exercise.git

Download and install STS for your OS: https://spring.io/tools/sts/all 下载并为您的操作系统安装STS: https//spring.io/tools/sts/all

Once it is installed and running. 一旦安装并运行。 Click on 'help -> Eclipse Marketplace' and search for the Google Cloud plugin. 单击“帮助-> Eclipse Marketplace”,然后搜索Google Cloud插件。 Install it. 安装它。

Install the Google Cloud SDK (I used linux instructions in my case) https://cloud.google.com/sdk/downloads#interactive 安装Google Cloud SDK(在我的情况下,我使用linux指令) https://cloud.google.com/sdk/downloads#interactive

Install the app-engine-java component , see here and then here 安装app-engine-java组件 ,请参见此处此处

After installing the components and authenticating In Google Cloud Platform. 在安装组件并在Google Cloud Platform中进行身份验证之后。 In Eclipse, click 'window -> preferences' and click on Google Cloud Tools (these are the preferences for the Google Cloud plugin). 在Eclipse中,单击“窗口->首选项”,然后单击Google Cloud Tools(这些是Google Cloud插件的首选项)。 In SDK location select the folder where you installed the SDK. 在SDK位置中,选择安装SDK的文件夹。 See image below. 参见下图。

在此处输入图片说明

Now you're ready to import the project with sts: 现在,您可以使用sts导入项目了:

Select 'new..project: Google App Engine Standard Project'. 选择“ new..project:Google App Engine标准项目”。

在此处输入图片说明

Click next. 点击下一步。 Uncheck 'Use default location' so you can select the folder that contains the git project you downloaded. 取消选中“使用默认位置”,以便您可以选择包含您下载的git项目的文件夹。

After importing. 导入后。 Right click on the project name and go to 'configure -> Convert to maven project' 右键单击项目名称,然后转到“配置->转换为Maven项目”

After maven solves all the imports, right click on the project name again and select 'Deploy to app engine standard'. 在maven解决了所有导入之后,再次右键单击项目名称,然后选择“部署到应用引擎标准”。 A window will open where you'll have to validate your account and choose a Google Cloud project. 将打开一个窗口,您需要在其中验证您的帐户并选择一个Google Cloud项目。

After deployment finishes you shoud be able to go to https://your-project-id.appspot.com/ 部署完成后,您应该可以访问https://your-project-id.appspot.com/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 访问spring启动应用程序.properties中提到的配置文件,在创建.jar后用于App引擎部署 - Access configuration file mentioned in spring boot application.properties after creating the .jar for App engine deployment Google App Engine上的Spring Boot应用程序:无法找到主类 - Spring Boot app on Google App Engine: unable to find main class 在tomcat中部署后无法访问spring boot应用程序 - Cannot access spring boot application after deployment in tomcat 初始部署后,将代码/ jar添加到Google App Engine应用程序 - Add code/jars to a google app engine application after initial deployment 部署后查看Google App Engine应用程序时出错 - Error when viewing Google App Engine application after deployment 为什么 Spring 启动应用程序在 Azure Web 应用程序上部署后不起作用 - Why Spring Boot Application is not working after Deployment on Azure Web app 在 Google Cloud App Engine 上构建 Spring Boot 应用程序的触发器 - Build trigger for Spring Boot application on Google Cloud App Engine 在 Google App Engine 上部署 Spring Boot 应用程序时出错 - Error while deploying spring boot application on google app engine Google App Engine 中的 Spring 启动应用程序 http 到 https 重定向 - Spring boot application http to https redirect in Google App Engine 使用 Gitlab CI 将 Spring 引导应用程序部署到 Google App Engine? - Deploy Spring Boot application to Google App Engine using Gitlab CI?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM