How to deploy Spring Boot application with PostgreSQL on the cloud Jelastic?

独自空忆成欢 提交于 2019-12-25 09:06:48

问题


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?


回答1:


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.




回答2:


ch, we are glad to notice you that we have published an article Hosting Spring Boot Standalone and Clustered Java Applications with Jelastic Cloud.

With Jelastic’s Spring Boot stack template, you can effortlessly run various Java-based applications inside the cloud via easy-to-use graphic interface or automation scripts. The following Java project types can be hosted within this server:

JAR – for standalone Java apps or stateless microservice instances, created using Spring Boot, Dropwizard or Spark frameworks

WAR – for web applications with embedded servlet container

Creation of Spring Boot Environment

So, log in to your Jelastic Cloud dashboard and let’s get started.

  1. First of all, you need to create a New Environment – use the same-named button to launch topology wizard. Switch to Java language tab and choose SpringBoot template within application server layer at the left-hand panel like shown below. Set the amount of allocated resources, type your environment name and click Create to proceed.

Versions Compatibility:

  • Indication with 1.x-2.x label implies that Jelastic-managed Spring Boot server can run any application, built upon these versions

  • The current custom Spring Boot stack is provisioned within Jelastic Platforms of 4.10 version and higher.

    1. When your new environment appears at the dashboard, you can click Open in browser to launch the pre-installed Hello World application sample.

In this way, you can make sure your Spring Boot instance is up and running.

Please follow the full instructions to see how to integrate your custom Java application into the created Spring Boot environment.



来源:https://stackoverflow.com/questions/43328762/how-to-deploy-spring-boot-application-with-postgresql-on-the-cloud-jelastic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!