Failed to bind properties under '' to com.zaxxer.hikari - java

I'm doing Spring Security and I'm trying to connecte my API with database to get user Authentication.
I don't know the error.
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:
Property: driverclassname
Value: com.mysql.cj.jdbc.Driver
Origin: "driverClassName" from property source "source"
Reason: com.mysql.cj.jdbc.Driver
Action:
Update your application's configuration
Process finished with exit code 1

It looks like HikariCP configuration issue. If you are using yml file for spring boot, the application.yml file should have the following contents.
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: <jdbc url specific to your database>
driver-class-name: <database url>
username: <username>
password: <password>
hikari:
idle-timeout: 10000
Please change the place holders as I have mention with angles <> as per the database.

Related

spring.profiles.active not working for all profiles

In my spring boot application, I have multiple profiles as below:
application.yml
application-dev.yml
application-local.yml
application-qa.yml
application-prod.yml
Each profile will have its own datasource configured. For testing purpose, same datasource configuration are passed in all profiles.
In application.yml if I mention spring.profiles.active=dev it is connecting to DB successfully. But if I mention spring.profiles.active=local then on server startup local profile is getting active with below error
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (the profiles lcl are currently active).
Below configuration passed in all profiles excluding application.yml
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
password: root
url: jdbc:mysql://localhost:3306/local_db?useSSL=false
username: root
jpa:
hibernate:
ddl-auto: update
show-sql: true
liquibase:
change-log: classpath:db/changelog/db.changelog-master.json

Spring, H2, R2DBC and Liquibase: /.testdb.trace.db: Read-only file system

When trying to start a Spring Boot application for tests (with H2 database) with R2DBC and Liquibase configured, I get the following error:
2022-10-04 12:50:18.893 INFO 57774 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 67 ms. Found 2 R2DBC repository interfaces.
org.h2.message.DbException: Log file error: "/.testdb.trace.db", cause: "java.nio.file.FileSystemException: /.testdb.trace.db: Read-only file system" [90034-214]
Here's my config:
spring:
liquibase:
change-log: classpath:liquibase/db.changelog.xml
contexts: production
url: jdbc:h2:file:///./.testdb;MODE=MySQL
r2dbc:
url: r2dbc:h2:file:///./.testdb
h2:
console:
enabled: false
Is there anything I can do to fix that error?
The problem was caused by the URL, R2DBC requires it to look like this:
r2dbc:
url: r2dbc:h2:file:///./.testdb
But then if you try to copy it over to Liquibase part, the error appears. To fix that, remove forward slashes from Liquibase URL:
spring:
liquibase:
change-log: classpath:liquibase/db.changelog.xml
contexts: production
url: jdbc:h2:file:./.testdb;MODE=MySQL
Final version:
spring:
liquibase:
change-log: classpath:liquibase/db.changelog.xml
contexts: production
url: jdbc:h2:file:./.testdb;MODE=MySQL
r2dbc:
url: r2dbc:h2:file:///./.testdb
h2:
console:
enabled: false

Issue in Running Jar file of Spring boot Gradle

I am not able to run the jar file of Spring Boot Gradle which I had created with ./gradlew clean bootJar jacocoMergeAll
and when I run in intellij with run button, I am able to run it.
and below is my commands which I had ran with intellij VM options which ran successfully but with jar this command does not work when I run the Jar file.
Below vm option is working one
-Dspring.profiles.active=local -Dserver.port=8080 -Dajp.port=0 -Dspring.datasource.url=jdbc:oracle:thin:#localhost:1521:OraDoc -Dspring.datasource.username=system -Dspring.datasource.password=MyPasswd123 -Dspring.config.additional-location=file:/Users/myUser/codebase/config/ -Dlogging.config=file:/Users/myUser/codebase/config/logback-spring.xml
Below running jar is not Working
java -Dspring.profiles.active=local -jar demo-0.1.0-SNAPSHOT.jar -Dserver.port=8080 -Dajp.port=0 -Dspring.datasource.url=jdbc:oracle:thin:#localhost:1521:OraDoc -Dspring.datasource.username=system -Dspring.datasource.password=MyPasswd123 -Dspring.config.additional-location=file:/Users/myUser/codebase/config/ -Dlogging.config=file:/Users/myUser/codebase/config/logback-spring.xml
I have tried with both -Dspring.datasource.url=jdbc:oracle:thin:#localhost:1521:OraDoc and -Dspring.datasource.url=jdbc:oracle:thin:#localhost:1521/OraDoc but none of this worked
when I run above jar command I get below error of not find the url
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (the profiles local are currently active).
my config file are under this directoy:
/Users/myUser/codebase/config/application.yml
/Users/myUser/codebase/config/application-local.yml
content of application.yml
server:
tomcat:
connectionTimeout: 300000
management:
endpoint:
mappings:
enabled: true
spring:
liquibase:
change-log: classpath:/db/changelog/db.changelog-master.xml
datasource:
driver-class-name: oracle.jdbc.driver.OracleDriver
hikari:
minimum-idle: 5
maximumPoolSize: 20
idleTimeout: 30000
maxLifetime: 2000000
connectionTimeout: 30000
poolName: factory-data-pool
jpa:
hibernate:
use-new-id-generator-mappings: false
ddl-auto: none
database-platform: org.hibernate.dialect.Oracle12cDialect
content of application-local.yml
server:
port: 8080
spring:
datasource:
url: jdbc:oracle:thin:#localhost:1521:OraDoc
username: system
password: MyPasswd123
liquibase:
contexts: local
Can someone please guide me on what wrong I am doing here?

Spring Boot 2.2.5 - spring.datasource.data property in yaml

Recently we upgraded to spring boot 2.2.5
We used to use the property spring.datasource.data to load SQL after "create" or "update" of the database.
Our Yaml looked like this:
--
spring:
profiles: default
application:
name:"EMBEDDED"
datasource:
url: "jdbc:postgresql://localhost/somedb"
driverClassName: org.postgresql.Driver
username: postgres
password: "some password"
data: "classpath*:data.sql"
jpa:
database: POSTGRESQL
show-sql: false
hibernate.ddl-auto: update
The important part is the "spring.datasource.data" property where we used to define a name of a SQL file that hibernate would run after updating the DB.
Note that we use the hibernate.ddl-auto to make that happen.
Now we have upgraded the spring boot and we also started using 2 data-sources as follows:
spring:
profiles: dev
application:
name:"EMBEDDED-DEV"
datasource:
src1:
jdbcUrl: "jdbc:sqlserver://localhost;databaseName=DB1"
username: user
password: password
initializationFailTimeout: 0
data: "classpath*:data.sql"
src2:
jdbcUrl: "jdbc:sqlserver://localhost;databaseName=db2"
username: user
password: password
initializationFailTimeout: 0
data: "classpath*:data.sql"
jpa:
database-platform: org.hibernate.dialect.SQLServer2012Dialect
show-sql: false
hibernate.format_sql: true
hibernate.ddl-auto: update
As you can see we have now 2 data sources, but when i try to add the "data" property as i used to do before i get this exception:
java.lang.RuntimeException: Property data does not exist on target class com.zaxxer.hikari.HikariConfig
Where should i put now the data property in order for it to work?

JHipster - Run spring boot with mvnw command

I am using a JHipster to create a spring boot application with PostgreSQL.
Actualy, when i execute the command mvnw the application-dev config file is "cleaned" to the initial properties.
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:postgresql://localhost:5432/test
username: test
password:
In this case, my database properties (user, password ...) are cleaned. I obtain the error:
"2017-08-06 18:17:10.726 ERROR 10844 --- [ restartedMain]
com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception
during pool initialization.
org.postgresql.util.PSQLException: The server requested password-based
authentication, but no password was provided."
Anyone can help me?
Need to put password into password .
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:postgresql://localhost:5432/test
username: test
password:<YOUR PASSWORD>

Categories