Whitelabel Error Page even though application.properties looks fine - java

Even though my application.properties looks fine when I go to
http://localhost:8080/h2-console I still get the whitelabel error page
My application.properties :
server:
port: 8080
Spring:
h2:
console:
enabled: true
path: /h2-console
onsole.settings.trace: false
scpring.h2.console.settings.web-allow-others: false
datasource:
url: jdbc:h2:mem:testdb
username: sa
password:
driverClassName: org.h2.Driver
jpa:
show-sql: true
defer-datasource-initialization: true
database-platform: org.hibernate.dialect.H2Dialect

White label errors occur when you don't have a mapping for /error. Check if you have the /h2-console route defined in one of your controller methods. If you have ensure all your classes are on the same folder level or deeper as your main class to ensure component scanning actually finds your classes.

Related

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

Hikari ActiveConnections & TotalConnections not shown in JMX bean

I am trying to get properties like ActiveConnections & TotalConnections from hikaricp using Visual VM. But am unable to view it in JMX bean. Below are the details of my app.
Spring boot 1.5.9
Java 8
gradle 6.6
HikariCP 3.3.1
What I have already tried in configuring.
spring:
profiles:
active: dev
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:teradata://****
username: ****
password: "****"
jmx-enabled: true
maximum-pool-size: 20
minimum-idle: 5
hikari:
poolName: mypool
register-mbeans: true
data-source-properties:
cachePrepStmts: true
prepStmtCacheSize: 250
prepStmtCacheSqlLimit: 2048
useServerPrepStmts: true
I am trying to configure it just by changing the app yml file. Is that possible?
Below is the screenshot of Visual VM. I have also checked this in jconsole but the metrics doesn't show up.
One this to notice here is that the pool name is not changing as per my parameter
[1]: https://i.stack.imgur.com/2qa8r.png
Please tell me what am I doing wrong here?

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?

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

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.

Categories