Java – spring boot gradle – where to place the environment configuration?

I am using a simple application in spring boot It is developed locally (and effective):

>Gradle, > H2 database, where the connection attribute is in application Set in properties and put it in the root directory of the project > Maven folder structure (SRC / main / groovy, Src / main / resources, etc.)

Now it's time for me to deploy it to openshift, so I need to create an additional production configuration with MySQL settings, but I don't know where to place it and how to use it

So my question is:

>How are two different configurations (development and production)? > Where to place the profile? > Do I have to build Change something in gradle? > How do I build an application using a development or production configuration? > How do I run an application using a development or production configuration? > What are the best practices for creating multiple environment configurations?

I am a front-end developer. All these back-end things are not obvious to me, so please consider it in your answer

This is my current build Content of gradle

plugins {
    id 'org.springframework.boot' version '1.5.3.RELEASE'
    id 'java'
    id 'groovy'
}

jar {
    baseName = 'myproject'
    version =  '0.0.1-SNAPSHOT'
}

repositories {
    jcenter()
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    testCompile("org.springframework.boot:spring-boot-starter-test")
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    compile 'MysqL:mysql-connector-java'
    compile("com.h2database:h2")
    compile("org.springframework.boot:spring-boot-starter-security")
    compile('io.jsonwebtoken:jjwt:0.7.0')
    compile localGroovy()
}

Solution

@H_ 502_ 36@

What should I do to have two different configurations (development and production)?

In your case, you can use a configuration file to implement it You can read it here For each configuration file, you can have a specific application properties file (named application -% profile_name%. Properties, similar to application-prod.properties, and the same is true for. YML configuration files), and you must specify what configuration file, and then use you to start your application through the command line switch, for example:

--spring.profiles.active=prod

Where to put the configuration files?

And application The properties file is located in the same location

Do I have to change something in the build. gradle?

No, you do not need to modify the build script Since all specific configurations are required to run the application, no build is required

How to build the app with a development or production config?

You don't need to build it with some specific configuration, just run it with it

How to run the app with a development or production config?

As mentioned earlier – just specify the profile to use when starting the application

What are the best practices for creating multiple environment configurations?

As for me, if you use spring - use configuration files and configuration file specific configuration and bean definitions

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>