Spring Boot - Outsource database settings

Asked

Viewed 165 times

-1

I have a JAVA project developed with Spring Boot.

Database settings are in the default file Resources/application.properties.

spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.driver-class-oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@//172.********:1521/BDHML
spring.datasource.username=********
spring.datasource.password=********

The application will run through the command:

java -jar **CONFIGURAÇÃO** app-cosolidar.jar

I need to put the database settings in a file . properties external to the project.

How can I do that?

How should the file . properties?

I must change some file. java?

What configuration should I put in java -jar?

Thank you,

Diego

1 answer

0

I decided to create a file called application properties, where are the settings for spring.datasource.

Then I created a script as follows:

#!/bin/bash

BASE_DIR=${PWD}
ADDITIONAL_APP_PROPERTIES="${BASE_DIR}/application.properties"    # Configuracoes da aplicacao - Spring Boot

java -Dspring.config.additional-location=${ADDITIONAL_APP_PROPERTIES} \
  -jar ${BASE_DIR}/app-cosolidar.jar

The JAR file is working properly this way.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.