如何在云端Jelastic上使用PostgreSQL部署Spring Boot应用程序? [英] How to deploy Spring Boot application with PostgreSQL on the cloud Jelastic?

查看:115
本文介绍了如何在云端Jelastic上使用PostgreSQL部署Spring Boot应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有Angular JS网络客户端和PostgreSQL数据库的简单Spring Boot应用程序。此时,我可以通过Maven为我的应用程序创建JAR或WAR。另外,我还有有效的Postgres数据转储。



有人可以给我一些路线图,以便我如何在Jelastic上成功托管我的应用程序和数据吗?

解决方案

首先,我的Jelastic提供者提供了大力支持,因此他们提供了很多帮助。



第一部分是用于部署应用程序(或者您可以从复制Postgres数据开始。这为您提供了必要的信息,以便您可以在部署之前更正application.properties您的应用程序)


  1. 支持人员建议使用其Maven插件进行构建。
    链接: maven-plugin-jelastic

  2. 您应该配置Application类,以便创建可部署的战争。
    链接:如何创建可部署的战争文件

  3. 请注意,必须禁用Spring Boot的嵌入式Tomcat。
    spring-boot-starter-web 依赖项启动嵌入式Tomcat,因此您可以通过以下方式禁用它:




 < dependency> 
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-web< / artifactId>
< exclusions>
< exclusion>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-tomcat< / artifactId>
< / exclusion>
< / exclusions>
< / dependency>





  1. 然后通过以下方式部署应用程序:




mvn jelastic:deploy





  1. 如果您像我一样拥有Angular Web客户端,则可能必须更正访问服务器所依据的基本URL。您没有端口,因此,如果在Jelastic上创建环境时设置了上下文名称,则应添加上下文名称。

例如,如果您在Jelastic中将上下文命名为 loc,则baseURL将为:

  angular.module('localizeApp')
.constant( baseURL, / loc /)

。 service('LocalizeData',['$ http','baseURL',function($ http,baseURL){

this.getConfig = function(){
return $ http.get( baseURL + config);
};

部署的一部分是在Jelastic上复制Postgres本地转储。


  1. 使用pgAdmin对Postgres数据库进行转储。

  2. 在创建环境时,使用Jelastic提供的信息转到Jelastic Postgres Web控制台。

  3. 使用以下命令创建新数据库

  4. 如果您的转储不是很大,请转到网络控制台中的 SQL部分,然后选择上传文件。文件。执行它。就是这样。

  5. 如果您的数据库很大,则可以通过SCP(请参见ssh连接)上载转储文件,并通过命令行导入。例如,支持人员推荐使用WinSCP。

然后您应该更正 application.properties

  spring.datasource.url = jdbc:postgresql:// your_jelastic_postgres_url / your_database 

还要设置正确的用户名和密码。


I have a simple Spring Boot application with Angular JS web-client and PostgreSQL database. At this point I can create JAR or WAR for my app by Maven. Also I have a valid dump of my Postgres data.

Could someone please give me some roadmap how I can successfully host my application and data on Jelastic?

解决方案

First of all my Jelastic provider has a great support so they helped a lot.

The first part is to deploy the application (or you might start with copying of your Postgres data. This gives you a neccessary information so that you can correct your application.properties before deploying your app)

  1. The support suggested to use their Maven plugin for build. The link: maven-plugin-jelastic
  2. You should configure Application class so that you can create a deployable war. The link: howto-create-a-deployable-war-file
  3. Pay attention that you have to disable embedded Tomcat of Spring Boot. The spring-boot-starter-web dependency starts embedded Tomcat, so you can disable this by:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>

  1. Then deploy your app by:

mvn jelastic:deploy

  1. If you have Angular web-client as I have, then you might have to correct base URL on which you access your server. You don't have a port, so you should add the context name if you set it during creating the environment on Jelastic.

For example if you name the context in Jelastic as "loc" then the baseURL will be:

angular.module('localizeApp')
    .constant("baseURL", "/loc/")

    .service('LocalizeData', ['$http', 'baseURL', function ($http, baseURL) {

        this.getConfig = function () {
            return $http.get(baseURL + "config");
        };

The second part of deployment is to copy your Postgres local dump on Jelastic. It is pretty simple.

  1. Make a dump of your Postgres database using pgAdmin.
  2. Go to Jelastic Postgres web-console using the information given to you by Jelastic when you create the environment there.
  3. Create new database with the proper name. Create user with password.
  4. If your dump is not very big then go to SQL section in the web-console and choose Upload a file. Choose your dump file. Execute it. That's all.
  5. If you have a big database then you can upload the dump file via SCP (see ssh connection) and import via command line. The support recommended WinSCP, for example.

Then you should correct application.properties:

spring.datasource.url=jdbc:postgresql://your_jelastic_postgres_url/your_database

Also set the right user and password.

这篇关于如何在云端Jelastic上使用PostgreSQL部署Spring Boot应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆