how to configure both mongodb and postgres in spring boot application.yml? - spring

We have spring boot project , in which we need to use mongo and postgres , but i thought am failing in configuring mongo and postgres details applicaiton.yml , below my what i configured , can any one please help me
spring:
profiles: stage
data:
mongodb:
host: mongodb-host
port: 27017
password: password
username: username
authentication-database: database
database: database
datasource:
driver-class-name: org.postgresql.Driver
url: postgres-url
username: user-name
password: password
tomcat:
validation-interval: 30000
test-on-borrow: true
validation-query: SELECT 1
when i start my spring-boot application , it is failing to start with below error
Caused by: java.lang.IllegalArgumentException: jdbcUrl is required with driverClassName.
can any one please help

Solution 1: remove spring.datasource.driver-class-name property
Solution 2: rename the spring.datasource.url property to spring.datasource.jdbc-url.
For solution 1 Spring Boot will figure out the default driver class name based on the spring.datasource.url property value.

Related

Spring Boot Liquibase doesn't appear to support XML formatted changelog

spring-boot-starter-parent:2.7.5
I have configured the following in my src/main/resources/application.yml file:
spring:
liquibase:
change-log: classpath:/db/changelog/db.changelog-master.xml
---
spring:
config:
activate:
on-profile: prod
datasource:
driver-class-name: org.postgresql.Driver
url: ${DB_URL}
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
Additionally, the following resource exists in the project repository:
src/main/resources/db/changelog/db.changelog-master.xml
I also have the following configured in src/test/resources/application.yml:
spring:
config:
activate:
on-profile: test
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
username: sa
password: sa
liquibase:
change-log: classpath:/db/changelog/db.changelog-master.xml
When I try to build this project the build fails with the following error message:
Liquibase failed to start because no changelog could be found at 'classpath:/db/changelog/db.changelog-master.yaml'
Is there some way to configure spring boot to allow an xml based liquibase changelog file? If so, what am I missing? Or does it only support the yaml format?
Your configurations seems valid, but some configuration still points to classpath:/db/changelog/db.changelog-master.yaml (based by on provided error message)
If there is no some typo, than may be you should look for this property in some other configuration (.properties files, command line arguments and other, see doc for all possible ways)

Not able to connect to H2 database in Spring Boot

I have the below in my yaml file.I keep getting the below error.how to resolve the below error.I am using latest spring boot version .
org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database
"C:/Users/mynname/test" not found, either pre-create it or allow
remote database creation (not recommended in secure environments)
[90149-214]
I can see the H2 console in http://localhost:8080/h2.But when i click on connect button i get the error.
spring:
h2:
console:
enabled: true
path: /h2
datasource:
url: jdbc:h2:mem:testdb
username: sa
password:
driverClassName: org.h2.Driver
jpa:
spring.jpa.database-platform: org.hibernate.dialect.H2Dialect
hibernate.ddl-auto: create
On the h2 console change the default ur that appears there (jdbc:h2:mem:test) to jdbc:h2:mem:testdb
And you should be able to connect

Quarkus Devservice for Oracle Database is not working

I am working on Quarkus Microservice application in which trying to use Quarkus Devservice to start Oracle DB with below configuration in application.yml file. But it's throwing exception.
application.yml:
quarkus:
datasource:
db-kind: oracle
username: root
password: password
devservices:
image-name: oracle
Exception:
Failed to load steps from class 'io.quarkus.devservice.oracle.deployment.OracleDevServicesProcessoer'

Spring cloud config not apply global configuration

I'm having a problem on spring cloud configuration 2020.0.3, spring boot 2.4.5 for details:
Yaml configuration file is following Multi-profile YAML documents
I have a configuration yaml file on the config server.
my_cofig.yaml
spring:
datasource:
url: "jdbc:mariadb://localhost:3306/default_db"
driver-class-name: org.mariadb.jdbc.Driver
username: my_db
password: 12345
---
spring:
profiles: dev
datasource:
url: "jdbc:mariadb://localhost:3306/dev_db"
I have loaded the config from the config server by browser, it's correct.
But:
When I run Spring application with specific configuration (e.g. dev), Spring application must not apply global configuration variables defined on configuration file from configuration server. It only loads dev's configuration variables.
bootstrap.yaml
server:
port: 8081
spring:
application:
name: auth-service
cloud:
config:
enabled: true
fail-fast: true
allow-override: true
profile: dev
uri: http://localhost:5000
Error detail:
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
Please help me, many thanks!
spring:
profiles:
This does not exist (it was deprecated if I am not mistaken). Please check the reference documentation.
I believe that what you are looking for is the following (reference documentation):
spring:
datasource:
url: "jdbc:mariadb://localhost:3306/default_db"
driver-class-name: org.mariadb.jdbc.Driver
username: my_db
password: 12345
---
spring:
config:
activate:
on-profile: dev
datasource:
url: "jdbc:mariadb://localhost:3306/dev_db"
Finaly, I solved the problem by upgrading spring boot version to 2.5.1
Thanks all

Spring Boot 1.3.5 with Hikari Connection Pool not able to set program name in v$session

I have a JHipster spring boot ver 1.3.5 application which connects to Oracle DB using Hikari Connection Pool. I am unable to set the program in v$session which should be possible by adding below in my application YAML
hikari:
v$session:
program: AppName
username: DB_USER
I have tried adding these at spring.datasource level, datasource.hikari level and datasource level.
I also looked at Hibernate 4.3.5 ignores v$session.program configuration property but that did not work as well.
Update 1 - I tried all the below and none seem to work
spring.datasource.hikari.datasourceProperties.v$session.program AppName
spring.datasource.hikari.datasourceProperties.v$session.username DB_USER
datasource.hikari.v$session.program AppName
datasource.hikari.v$session.username DB_USER
datasource.hikari.datasourceProperties.v$session.program AppName
datasource.hikari.datasourceProperties.v$session.username DB_USER
hikari.v$session.program AppName
hikari.v$session.username DB_USER
hikari.datasourceProperties.v$session.program AppName
hikari.datasourceProperties.v$session.username DB_USER
Following works in Spring Boot 1.5.8.RELEASE using application.yml file:
spring:
datasource:
hikari:
data-source-properties:
v$session.program: AppName
In Spring Boot 2 use:
spring:
datasource:
hikari:
data-source-properties:
"[v$session.program]": AppName

Resources