I have a property like below in Spring Boot application.properties:
spring.datasource.url=jdbc:mysql://localhost:3306/my_db?serverTimezone=UTC&connectTimeout=10000&socketTimeout=30000
In here, I want to give "connectTimeout=10000&socketTimeout=30000" arguments with other properties like:
db.myprops=connectTimeout=10000&socketTimeout=30000
spring.datasource.url=jdbc:mysql://localhost:3306/my_db?serverTimezone=UTC&{db.myprops}
How can I handle it or Is there a specific properties in Spring Boot for connectTimeout and socketTimeout?
Solution by OP.
To call it as other property in Spring-Boot Configuration:
spring.application.property.1=property1
spring.application.property.2=property2${spring.application.property.1}
Then we can call it from Java environment to customize it like below:
java -Dspring.application.property.1=custom -jar ../*.jar
if you use JPA spring uses Hikari as the underlying database connection pool
//example configuration
spring.datasource.hikari.connectionTimeout=30000
spring.datasource.hikari.idleTimeout=600000
spring.datasource.hikari.maxLifetime=1800000
Hikari configuration knobs Spring Documentation
Related
I'm new using springboot and I've been triying to configure a project with it and spring security, but unfortunately I'm not able to run it. I'm getting the next error :
nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
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
I've been looking for a solution but I can't find anything that fit in my project.
Please, any idea?
You can see the project here :
Proyect
Thanks
In application.properties, Change
app.datasource.jdbc-url
app.datasource.username
app.datasource.password
app.datasource.driver-class-name
To
spring.datasource.url
spring.datasource.username
spring.datasource.password
spring.datasource.driver-class-name
How to write logback.xml for Micronaut, like Spring Boot:
https://www.logicbig.com/tutorials/spring-framework/spring-boot/profile-logback-logging-config.html
I think springProfile doesn't exist in Micronaut.
I have Micronaut environments and I want to use these for example change logging format only per Micronaut environment.
Best regards
Imre
https://github.com/micronaut-projects/micronaut-examples/blob/master/websocket-chat/src/main/resources/logback.xml
Recently, I ported my spring boot application to Micronaut and used the same logback.xml as given above. Hope this helps.
I have a Spring boot app I'm trying to add database logging to which is better than
spring.jpa.properties.hibernate.show_sql=true
log4jdbc, from
https://github.com/marcosemiao/log4jdbc
seems to be the most up to date fork around, seems to format nicely, fills in parameters and adds timing, exactly what I want.
But when I configure it as stated in the readme, changing
spring.datasource.url=jdbc:mysql://localhost:3306/coindatabase?useSSL=false
to
spring.datasource.url=jdbc:log4jdbc:mysql://localhost:3306/coindatabase?useSSL=false
something seems to not like my reference to mysql and seems to try to fall back to H2:
Caused by: java.lang.RuntimeException: Driver org.h2.Driver claims to not accept jdbcUrl, jdbc:log4jdbc:mysql://localhost:3306/coindatabase?useSSL=false
at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:106)
Is there some easy way to make this work together?
log4jdbc for spring boot wrapper:
<groupId>com.integralblue</groupId>
<artifactId>log4jdbc-spring-boot-starter</artifactId>
which seems to pull in the implementation from:
<groupId>org.bgee.log4jdbc-log4j2</groupId>
<artifactId>log4jdbc-log4j2-jdbc4.1</artifactId>
Additional info:
Don't modify the spring.datasource.url property in your Spring Boot application.properties file; leave the URL as previously defined to access your MYSQL instance.
Instead, after grabbing the com.integralblue maven target, simply set the logging level of choice (ex logging.level.jdbc.sqltiming=info) and your previously defined log4j log will have the DB stuff in it.
See here as was well
You need to use this library in your build.gradle:
// https://mvnrepository.com/artifact/com.integralblue/log4jdbc-spring-boot-starter
compile group: 'com.integralblue', name: 'log4jdbc-spring-boot-starter', version: '2.0.0'
If you get the warning:
"Loading class 'com.mysql.jdbc.Driver'. This is deprecated. The new driver class is 'com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary."
you can set the correct Driver yourself via properties:
log4jdbc.drivers=com.mysql.cj.jdbc.Driver
log4jdbc.auto.load.popular.drivers=false
The documentation for configuration can be found on Github
Is there a way to use application.json file in Spring Boot the same way as application.properties and application.yml for configuration?
No.
The official spring documentation does not say there is as of spring boot 1.5.1 RELEASE.
Properties & Configuration
The only JSON related wording in Properties & configuration section is:
YAML is a superset of JSON and as such is a very convenient syntax for storing external properties in a hierarchical format
My Java EE 6 application uses slf4j with logback as logging framework. I have openjpa custom logging which is not working on Weblogic while it was ok on glassfish before (whit openjpa 1.2).
When I add my custom log factory to "openjpa.log" property in persistence.xml, weblogic ignores this and doesn't work.
my custom log factory:
<property name="openjpa.Log" value="com.kishware.core.log.openjpa.CustomSLF4JLogFactory"/>
Here is the weblogic console output when ignores the property:
<Aug 17, 2013 11:29:35 AM GMT+04:30> <Warning> <J2EE> <BEA-160202> <You have specified a openjpa.Log setting in your configuration for persistence unit banco-product#pu-channel-manager. This setting will be ignored and all log messages will be sent to the WebLogic Server logging subsystem. Trace-level logging is controlled by the various JPA-specific debug settings in config.xml, or through the WebLogic Server Administration Console.>
I should mention that I'm using JPA 2.1 with Toplink implementation.
I would be happy to get some hints, how this could be solved.
I should mention that I'm using JPA 2.1 with Toplink implementation
Right there is your problem. You're trying to configure Toplink (and I think you mean EclipseLink) with OpenJPA configuration properties.