SpringBoot Mongo config being ignore by application.yaml - spring-boot

Having a really annoying issue with my Spring Boot API.
So I have a MySQL db and a MongoDB which I connect to. Everything with the Mysql works fine i.e. the settings from the Application.yaml file but not Mongo. It ignores the Database name and creates its own one called "test". Even if I put in a random host and port it still connects locally. Anyone able to spot what i'm doing wrong?
server:
servlet:
contextPath: /api/v1/
port: 8080
spring:
data:
mongo.database: springboot-rest
mongo.host: localhost
mongo.port: 27017
output:
ansi:
enabled: ALWAYS
datasource:
url: jdbc:mysql://localhost:3306/spring_social?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
username: test
password: test
servlet:
multipart:
max-file-size: -1
max-request-size: -1
jpa:
show-sql: true
hibernate:
ddl-auto: update
naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy
properties:
hibernate:
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
EDIT worth noting i also tied this way with no luck either:
spring:
data:
mongo:
database: springboot-rest
host: localhost
port: 27017
output:
ansi:
enabled: ALWAYS
datasource:
url: jdbc:mysql://localhost:3306/spring_social?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
username: test
password: test

mongodb should be there instead of mongo
spring:
data:
mongodb:
database: springboot-rest

Related

My spring boot project can't access RDS DB instance used on EC2 instance

I can access to RDS DB instance, which uses EC2 instance, by using SSH private key on MySQL Workbench. But on Intellij, I couldn't access to database to run spring boot application. How can I run this project on my local with RDS DB on Intellij?
The application-local.properties looks following.
...
cloud:
aws:
credentials:
accessKey: xxx
secretKey: xxx
s3:
bucket: my-develop
region:
static: ap-northeast-2
spring:
servlet:
multipart:
max-file-size: 50MB
max-request-size: 50MB
security:
enabled: false
oauth2:
client:
registration:
google:
client-id: xxxxx.apps.googleusercontent.com
client-secret: xxxxx
facebook:
client-id: xxxxxx
client-secret: xxxx
mvc:
view:
prefix: /WEB-INF/view/
suffix: .jsp
devtool:
livereload:
enabled: true
jackson:
serialization:
fail-on-empty-beans: false
default-property-inclusion: always
datasource:
url: jdbc:mysql://my-database.xxxx.ap-northeast-2.rds.amazonaws.com:3306/my_database?characterEncoding=utf-8&serverTimezone=UTC
username: user
password: password
driverClassName: com.mysql.cj.jdbc.Driver
platform: mysql
initialization-mode: always
hikari:
connection-timeout: 5000
validation-timeout: 1000
minimum-idle: 20
maximum-pool-size: 20
max-lifetime: 30000
leak-detection-threshold: 10000
idle-timeout: 10000
"I can access to RDS DB instance, which uses EC2 instance, by using SSH private key on MySQL Workbench." It sounds like you are using an EC2 instance as a bastion host or "jump box" to access a private RDS database. You would need to use SSH port forwarding to accomplish the same thing for your local Spring Boot application.

How do I setup JavaFX with SpringBoot desktop application to share database on a LAN

I have an inventory management application built with JavaFx and springboot that was originally built to run as standalone using hsqldb. Now I want to upgrade it so that two or more systems can share same database in a LAN environment. When I connect two systems via wifi, I could run the application from the other connected computer but after creating a record, it did not reflect on the other system. Please how do I make this work? Do I need to use mysql instead of hsqldb?
Below is my application.yml file configuration. The lines hashed out are the previous setting for the stand alone version and I have re-defined the hsql settings to use a network path as shown (\PC001\ims_compiled\shared_hsqldb\hsqldb)
Please any assistance ill be appreciated
app:
fixedDelay: 300000
fixedRate: 1200000
localLogin: true
debug: true
hsql:
parameters: hsqldb.lock_file=false;createDatabaseIfNotExist=true;DB_CLOSE_DELAY=-1;shutdown=true;hsqldb.write_delay=false;hsqldb.write_delay_millis=100
log4j:
logger:
org:
hibernate:
transaction: ERROR
springframework:
transaction: ERROR
logging:
config: logback.xml
level:
com:
zaxxer:
hikari:
HikariConfig: ERROR
org:
hibernate:
SQL: ERROR
type:
descriptor:
sql:
BasicBinder: ERROR
mysql-base:
datasource:
DB: ikooba_db
host: 34.244.38.76
jdbc-url: jdbc:mysql://${mysql-base.datasource.host}:${mysql-base.datasource.port}/${mysql-base.datasource.DB}?${mysql-base.datasource.parameters}
parameters: serverTimezone=UTC&useSSL=FALSE&autoReconnect=true&sessionVariables=sql_mode=''
password: 'gsjgsgssshj'
port: 3306
username: sfgsdsfdfs
sentry:
dsn: https://shfs6765676757shsvvs#errors.xxxxxxxx.com/6
enabled: true
stacktrace:
app:
packages: com.ikooba.desktop.ims
spring:
datasource:
hikari:
auto-commit: true
# jdbcUrl: jdbc:hsqldb:hsqldb/userDB;${hsql.parameters}
jdbcUrl: jdbc:hsqldb:\\PC001\ims_compiled\shared_hsqldb\hsqldb/userDB;${hsql.parameters}
password: ''
username: sa
jpa:
hibernate:
ddl-auto: update
use-new-id-generator-mappings: true
properties:
hibernate:
enable_lazy_load_no_trans: true
jdbc:
batch_size: 120
order_inserts: true
search:
default:
directory_provider: filesystem
# indexBase: hsqldb/lucence/indexes
indexBase: \\PC001\ims_compiled\shared_hsqldb\hsqldb/lucence/indexes
indexwriter:
infostream: true
generate_statistics: true
jmx_enabled: true
lucene_version: LATEST
javax:
persistence:
validation:
mode: none
main:
allow-bean-definition-overriding: true
lazy-initialization: true
Setup a HSQLDB server on PC001 and connect to it from different machines.
Chapter 15. http://hsqldb.org/doc/2.0/guide/listeners-chapt.html#lsc_hsql_server
For simplicity, create a server.properties file as described. Inside this file the property setting below should reflect the name, path, and the startup properties of your databse. For example:
server.database.0=file:\\PC001\ims_compiled\shared_hsqldb\hsqldb/userDB;hsqldb.write_delay_millis=100
The other parameters that you used in your hsql.parameters are unnecessary (e.g. hsqldb.lock_file, shutdown). See http://hsqldb.org/doc/2.0/guide/dbproperties-chapt.html for valid properties (but you probably don't need them).

Default value for profiles in Spring Boot

I have multiple profiles and there are lots of attributes(which will grow), I don't want to set each attribute every time in a different profile.
I have an application.yml file like this:
freemarker:
template-loader-path: classpath:/templates
datasource:
username: postgres
password: mypass
driver-class-name: org.postgresql.Driver
jpa:
show-sql: true
properties:
hibernate:
jdbc:
lob:
non_contextual_creation: true
dialect: org.hibernate.dialect.PostgreSQLDialect
hibernate:
ddl-auto: create
security:
secret: "jwt_secret_key_it_is_a_random_key_229"
loginTokenExpiration: 86400
confirmUserTokenExpiration: 86400
devTokenExpiration: 157680000
tokenPrefix: "Bearer"
headerString: "Authorization"
signUpUrl: "/token/login"
mysite:
apiTosUrl: "https://example.com/api-tos"
fromEmail: "alert#example.com"
firstFreeCredits: 10
junction:
port: 9080
hasBasicAuth: false
---
spring:
profiles:
active: dev
---
spring:
profiles: stage
jpa:
show-sql: true
hibernate:
ddl-auto: update
chargeBee:
site: "example.chargebee.com"
apiKey: "mykey"
---
spring:
profiles: prod
datasource:
url: jdbc:postgresql://localhost/myproddb
jpa:
show-sql: false
hibernate:
ddl-auto: update
chargeBee:
site: "example.chargebee.com"
apiKey: "myapikey"
Most of the settings are common between profiles, and which are not common, I have re-defined it in the corresponding section of the profile.
I am assuming that the first section in this YAML document fills the properties with default values and the corresponding sections overwrite it.
Is this approach correct? If not then how to have an inheritance of properties values such that I define the common value once and for the rest of the profiles, I only need to define the different values?
you can also achieve profile using create the different profile-specific yml file.
you can also be defined by using the following naming convention:
application-{profile}.yml
Create application.yml file. This file loaded first. Load all attribute of application.yml file.
Check any active profile found(yes stage) then load after successfully load default profile then load application-stage.yml file and override existing attribute and add the new attribute.
spring:
profiles:
active: stage
datasource:
url: jdbc:postgresql://localhost:5432/springbootdb
create application-stage.yml file same location of application.yml.
spring:
jpa:
show-sql: true
hibernate:
ddl-auto: update
chargeBee:
site: "example.chargebee.com"
apiKey: "mykey"
create application-prod.yml file same location of application.yml.
spring:
datasource:
url: jdbc:postgresql://localhost/myproddb
jpa:
show-sql: false
hibernate:
ddl-auto: update
chargeBee:
site: "example.chargebee.com"
apiKey: "myapikey"
Yes that correct approach to define multiple profiles
You can specify multiple profile-specific YAML documents in a single
file by using a spring.profiles key to indicate when the document
applies, as shown in the following example:
See official document 24.6.3 Multi-profile YAML Documents
In the below example, if the development profile is active, the server.address property is 127.0.0.1. Similarly, if the production profile is active, the server.address property is 192.168.1.120. If the development and production profiles are not enabled, then the value for the property is 192.168.1.100.
server:
address: 192.168.1.100
---
spring:
profiles: development
server:
address: 127.0.0.1
---
spring:
profiles: production
server:
address: 192.168.1.120

Change Spring JPA repository to one related to HIVE/HADOOP

I am working on a project integrating Hadoop, Hive and accessing it via Spring.
Currently my project works with a default Spring repository: "org.springframework.data.jpa.repository.support.SimpleJpaRepository#757b7c0a" but I would want to work with a repository able to understand HIVE queries.
For example, inserting a user into a HIVE database.
Actually I have a connection to HIVE in my project but everything is chaos and nothing works and I believe it is because the repository I am using is not the correct one.
So my question is ... how, where and what values to insert in order to change that repository for a Hive-friendly one ?
I have this in my application.yml:
spring:
profiles:
include: swagger, no-liquibase
devtools:
restart:
enabled: true
livereload:
enabled: false # we use gulp + BrowserSync for livereload
datasource:
type: org.springframework.jdbc.datasource.DriverManagerDataSource
url: jdbc:hive2://localhost:10000/default;DB_CLOSE_DELAY=0
username: catalin
password:
default-auto-commit: true
jpa:
show-sql: true
properties:
hibernate:
format_sql: true
mail:
host: localhost
port: 25
username:
password:
thymeleaf:
cache: false
liquibase:
contexts: hive
Thank you.

Database application.yml for Spring boot from applications.properties

I've got a working Spring Boot Application that connects to a Postgres database. I've got the project set up with an application.properties file, but would like to make the switch over to an application.yml file. However when I make the switch, my application errors out while attempting to connect to the db.
Original applications.properties file:
spring.jpa.database=POSTGRESQL
spring.datasource.platform=postgres
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.database.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
spring.datasource.username=foo
spring.datasource.password=bar
And Here's what I've got so far in the application.yml file:
spring.jpa:
database: POSTGRESQL
hibernate.ddl-auto: create-drop
show-sql: true
spring.datasource:
platform: postgres
driverClassName: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/mydb
username: foo
password: bar
Am I missing something in the translation between file types?
You need to treat each . character in property names as levels in the yaml file:
spring:
jpa:
database: POSTGRESQL
show-sql: true
hibernate:
ddl-auto: create-drop
datasource:
platform: postgres
url: jdbc:postgresql://localhost:5432/mydb
username: foo
password: bar
driverClassName: org.postgresql.Driver
EDIT: edits have been suggested, thanks for that. The driverClassName property actually should be under spring.datasource. However, the purpose of this answer was to show how a properties file is converted into yaml format. So I have changed the driverClassName property to be at the right path, that is not part of the transformation from properties to yaml.
Please upvote the other answer (Z0lt#n's answer)
But pasting here for future readers... a sql server version.
spring:
jpa:
show-sql: true
hibernate:
ddl-auto: update
properties:
hibernate.jdbc.batch_size: 20
hibernate.cache.use_query_cache: false
hibernate.cache.use_second_level_cache: false
hibernate.cache.use_structured_entries: false
hibernate.cache.use_minimal_puts: false
datasource:
#SPRING_DATASOURCE_URL environment variable will be something like -> jdbc:sqlserver://MySqlServer\\MyInstance:1433;DatabaseName=MyDbName;
url: ${SPRING_DATASOURCE_URL}
username: ${SPRING_DATASOURCE_USERNAME}
password: ${SPRING_DATASOURCE_PASSWORD}
driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
and maven entry
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.0.0.jre8</version>
</dependency>
APPEND
This seems to be the "standard" name for the driverClassName.
SPRING_DATASOURCE_DRIVER-CLASS-NAME
And of course, in my example, you would use the value of:
com.microsoft.sqlserver.jdbc.SQLServerDriver
NOW, some spring, springboot, environment variable voodoo alert.
Sometimes, when specifying the environment variable...for some command lines items, I would have to change the hyphens and make them underscores.
(aka, "SPRING_DATASOURCE_DRIVER-CLASS-NAME" vs "SPRING_DATASOURCE_DRIVER_CLASS_NAME"
below the -e generically represents "passing environment variable values via the command line"
MyCommandLineProgram.exe -e SPRING_DATASOURCE_URL="jdbc:sqlserver://myServerName:1433;DatabaseName=MyDB;" -e SPRING_DATASOURCE_USERNAME="myUserName" -e SPRING_DATASOURCE_PASSWORD="myPassword" -e SPRING_DATASOURCE_DRIVER_CLASS_NAME="com.microsoft.sqlserver.jdbc.SQLServerDriver"
There's some voodoo for you.
Those interested in the logging (logback.xml) issue, maybe want to find my answer here as well:
Spring Boot Logback DB Appender Properties
application.yml file for postgresql
Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring:
datasource:
driver-class-name: org.postgresql.Driver
username: postgres
password: root
url: jdbc:postgresql://localhost/postgres
platform: postgres
initialization-mode: always
continue-on-error: true
jpa:
show-sql: true
generate-ddl: true
hibernate:
ddl-auto: create
database: postgresql
server:
port: 1111
spring:
application:
name: client-one
datasource:
password: postgres
url: jdbc:postgresql://localhost:5432/postgres?currentSchema=education
username: postgres
jpa:
hibernate:
ddl-auto: update
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
show-sql: true

Resources