Configuring application using application.yaml instead of application.properties - quarkus

I have a small Quarkus 1.1.0.Final Web application (using Java 1.8). I'm trying to use a YAML file to configure the application (instead of the usual application.properties) but there is no way the application comes up. I'm always getting this not-so-useful error message(s):
13:53:32,494 ERROR [io.qua.dev.DevModeMain] Failed to start Quarkus: java.lang.RuntimeException: io.quarkus.builder.ChainBuildException: No producers for required item class io.quarkus.deployment.builditem.BuildTimeRunTimeFixedConfigurationBuildItem
at io.quarkus.runner.RuntimeRunner.run(RuntimeRunner.java:180)
at io.quarkus.dev.DevModeMain.doStart(DevModeMain.java:177)
at io.quarkus.dev.DevModeMain.start(DevModeMain.java:95)
at io.quarkus.dev.DevModeMain.main(DevModeMain.java:66)
Caused by: io.quarkus.builder.ChainBuildException: No producers for required item class io.quarkus.deployment.builditem.BuildTimeRunTimeFixedConfigurationBuildItem
at io.quarkus.builder.BuildChainBuilder.build(BuildChainBuilder.java:240)
at io.quarkus.deployment.QuarkusAugmentor.run(QuarkusAugmentor.java:112)
at io.quarkus.runner.RuntimeRunner.run(RuntimeRunner.java:113)
... 3 more
13:53:32,519 INFO [io.qua.dev.DevModeMain] Attempting to start hot replacement endpoint to recover from previous Quarkus startup failure
13:53:32,532 ERROR [io.qua.dev.DevModeMain] Failed to start quarkus: java.lang.IllegalArgumentException: workerPoolSize must be > 0
at io.vertx.core.VertxOptions.setWorkerPoolSize(VertxOptions.java:275)
at io.quarkus.vertx.core.runtime.VertxCoreRecorder.convertToVertxOptions(VertxCoreRecorder.java:151)
at io.quarkus.vertx.core.runtime.VertxCoreRecorder.initializeWeb(VertxCoreRecorder.java:104)
at io.quarkus.vertx.http.runtime.VertxHttpRecorder.startServerAfterFailedStart(VertxHttpRecorder.java:115)
at io.quarkus.vertx.http.deployment.devmode.VertxHotReplacementSetup.handleFailedInitialStart(VertxHotReplacementSetup.java:30)
at io.quarkus.dev.RuntimeUpdatesProcessor.startupFailed(RuntimeUpdatesProcessor.java:449)
at io.quarkus.dev.DevModeMain.doStart(DevModeMain.java:191)
at io.quarkus.dev.DevModeMain.start(DevModeMain.java:95)
at io.quarkus.dev.DevModeMain.main(DevModeMain.java:66)
This is my YAML file:
#
# https://quarkus.io/guides/all-config
# https://quarkus.io/guides/config#overriding-properties-at-runtime
quarkus:
datasource:
driver: org.postgresql.Driver
flyway:
migrate-at-start: true
health:
extensions:
enabled: true
hibernate-orm:
dialect: org.hibernate.dialect.PostgreSQL10Dialect
http:
port: 8080
log: # ALL > FINEST > FINER > FINE > CONFIG > INFO > WARNING > SEVERE > OFF
console:
async: true
color: true
enable: true
format: "%d{yyyy-MM-dd HH:mm:ss,SSS} |- %-5p in %c:%L{3.} [%t] - %s%e%n"
level: WARNING
resteasy:
path: /api
smallrye-openapi:
path: /open-api
swagger-ui:
always-include: true
path: /swagger-ui
"%dev":
quarkus:
datasource:
password: postgres
url: jdbc:postgresql://localhost:5432/quarkus_web
username: postgres
flyway:
clean-at-start: true
hibernate-orm:
log:
sql: true
statistics: true
log:
category:
"io.quarkus.arc.processor":
level: OFF
"io.quarkus":
level: INFO
"org.acme":
level: CONFIG
"%prod":
quarkus:
datasource:
password: postgres
url: jdbc:postgresql://localhost:5432/quarkus_web
username: postgres
flyway:
clean-at-start: false
hibernate-orm:
database:
generation: none
sql-load-script: no-file
"%test":
quarkus:
datasource:
password: postgres
url: jdbc:postgresql://localhost:5432/quarkus_web
username: postgres
flyway:
clean-at-start: true
log:
category:
"io.quarkus":
level: WARNING
"org.acme":
level: WARNING
Anyone using this approach already and succeeded? I'm including io.quarkus:quarkus-config-yaml:1.1.0.Final.
One thing that I've noticed is that I can't separate the profiles using --- as I do with Spring Boot. I think I should file an issue for this :thinking_face:

It certainly looks like a bug, maybe even 2 as the second error message doesn't look like something I would expect considering your configuration file.
Could you create a bug in our tracker: https://github.com/quarkusio/quarkus/issues/new?assignees=&labels=bug&template=bug_report.md&title= ?
It would be nice if you could provide a reproducer. AFAICS, Quarkus doesn't start at all so probably your pom.xml with the various extensions you use and your configuration file should be enough to reproduce the issue.

Turns out this was not an issue. I just had an old Gradle config; some things changed with the Gradle plugin with version 1.1.0.Final and I just didn't have those.

Related

Failed to determine suitable jdbc url when deploy on gitlab

When I run the application locally, it works.
When I deploy the master branch in gitlabs's CI/CD pipeline it works too.
But when I run the deploy to other branch it launch an 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 suitable jdbc url
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 stag are currently active).
My application.yml:
datasource:
driver-class-name: org.postgresql.Driver
url: ${POSTGRES_URL}
username: ${POSTGRES_USER}
password: ${POSTGRES_PASS}
hikari:
connectionTimeout: 20000
idleTimeout: 20000
maxLifetime: 60000
maximum-pool-size: 10
jpa:
hibernate:
show-sql: true
ddl-auto: validate
properties:
hibernate:
globally_quoted_identifiers: true
dialect: org.hibernate.dialect.PostgreSQL10Dialect
show_sql: true
format_sql: true
database-platform: org.hibernate.dialect.PostgreSQL10Dialect

Spring boot application - failed to start

I have recently upgraded spring boot from 1.x to 2.2.1. I am able to deploy most of the modules. For one of the modules I am getting below error while deploying in openshift.
***************************_APPLICATION FAILED TO START_***************************__Description:__Failed to bind properties under 'spring.jackson.serialization' to java.util.Map<com.fasterxml.jackson.databind.SerializationFeature, java.lang.Boolean>:__ Reason: No converter found capable of converting from type [java.lang.String] to type [java.util.Map<com.fasterxml.jackson.databind.SerializationFeature, java.lang.Boolean>]__Action:__Update your application's configuration_
I have added jackson-databind and jackson-core dependencies but no luck.
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.11.1</version>
</dependency>
In local environment the deployment works fine.
application.yml:
application:
name: #project.name#
server:
port: 8085
context: /*
sessionAPIUrl: localhost:8087
sessionAPIUri: /AppMS/user/session
account:
host: http://localhost:8080
remote:
dev: http://localhost:8080
test: http://10.8.99.8:8080
staging: https://stg2-tic.myapp.com
prod: https://ss1.myapp.com
uri:
data: AppMS/service/test
javax.persistence.query.timeout: 120000
#mongodb
spring.data.mongodb.authentication-database:
spring.data.mongodb.host:
spring.data.mongodb.port: 22017
spring.data.mongodb.database: ticnf
spring.data.mongodb.username: ******
spring.data.mongodb.password: ******
#JMX setting
endpoints.jmx.unique-names: true
#logging setup
logging.level.org.springframework.web: WARN
logging.level.com.myapp: INFO
# Logging pattern for the console
logging.pattern.console: "%d{dd-MMM-yyyy HH:mm:ss:SSS zzz}, TYPE= %-5p, SESSIONID=%X{sessionID}, CLIENT_IP=%X{UserIPAddress}, REQID=%X{requestID}, SSOUID=%X{ssoUserId}, ticUID=%X{ticUserID}, APP=%X{APP}, REQUESTURI=%X{requestURI}, CLASS=%c{1}, METHOD=%M, MSG=%m%n"
# Logging pattern for file
logging.pattern.file: "%d{dd-MMM-yyyy HH:mm:ss:SSS zzz}, TYPE= %-5p, SESSIONID=%X{sessionID}, CLIENT_IP=%X{UserIPAddress}, REQID=%X{requestID}, SSOUID=%X{ssoUserId}, ticUID=%X{ticUserID}, APP=%X{APP}, REQUESTURI=%X{requestURI}, CLASS=%c{1}, METHOD=%M, MSG=%m%n"
logging.file: logs/ticms/ticms.log
#kafka configuration
kafka:
broker:
address: localhost:9099
zookeeper:
connect: localhost:2191
consumerId: tic.account
tic.secret: where to store this is an question? DB/File?
spring:
profiles: dev
jackson:
serialization:
INDENT_OUTPUT: true
datasource:
driver-class-name: com.ibm.db2.jcc.DB2Driver
url: jdbc:db2://192.0.0.1:9000/sdb1:currentSchema=DEV1;
username: *****
password: *****
platform: db2
schema: classpath:schema-db2-stg.sql
jpa:
show-sql: true
properties:
hibernate:
dialect: org.hibernate.dialect.DB2Dialect
default_schema: DEV1
server:
domainURI: https://stg-us-api.myapp.com/oauth2/v1
log4j.logger.org.hibernate.type: trace
org.hibernate.type: trace
org.springframework.transaction: debug```
Thank you everyone.
When I saw the error message saying "_Update your application's configuration" , I was sure something is wrong in my application.yml. But in local it was deploying fine.
In paas it was failing, hence I tried to check all the paas related config files. paas-pom was ok. FInally I found application-paassit.yml file was missing. This file was mentioned in my config map for that application in openshift.
I added the file and it was solved.

how to rotate log file in spring boot

I tried to create a log file configuration that creates a new log file when it sized by 20MB. I'm using the application.yaml file . I've searched for this file configuration in docs and in the internet but didn't work im my machine. I also tried another approaches like the location of the file , the delimiters ( change by / ) , and the hierarchy of the properties in the application.yaml.
so my file configuration its like :
server:
port: 8080
logging.file: D:\logs\logfile.txt
logging:
file:
max-history: 20
max-size: 50MB
level:
org.springframework.web: DEBUG
org.hibernate: DEBUG
spring:
mvc:
throw-exception-if-no-handler-found: true
resources:
add-mappings: false
security:
basic:
enable: false
server:
contextPath: /
datasource:
url: jdbc:postgresql://servername.myent.com:5432/appname
username: meandmsjake
password: 123abc
driver-class-name: org.postgresql.Driver
type: com.zaxxer.hikari.HikariDataSource
hikari:
maximum-pool-size: 20
idle-timeout: 10000
jpa:
#database-platform: org.hibernate.dialect.PostgreSQLDialect
database-platform: org.hibernate.spatial.dialect.postgis.PostgisDialect
show-sql: true
properties:
hibernate:
temp:
use_jdbc_metadata_defaults: false
hibernate:
ddl-auto: none
There appear to be two issues here:
I'm not sure that setting both logging.file and logging.file.max-history will work in yaml, considering the tree structure. To remedy this, I would try to put these particular properties in the yaml.
I don't believe that server.logging.file is the correct property (as you have it here). It should be simply logging.file. Accordingly, the other properties should not be prefixed with "server".
That said, it would be helpful if you posted the version of Spring Boot that you are using.

Problem with port determination using spring cloud

I have created 2 instances of a microservice named InfyGo_Flights. I have put a yaml file in git hub with
server.port 9004. My properties file in MS is empty apart from application name. These 2 instances have 2 diff issues:
1.First I overrode in the config itself to take server.port as 9010. But still ran on 9004. I deleted the server.port in yaml in github. But this caused it to run into error. So replaced it with 9004 again. But now it has started running on 9010. Removing the overridden property causes it to run into error.
2.Second config I created after the first one was causing issue. But despite the yaml file in cloud config it runs on default 8080 port.
application.properties:
spring.application.name=InfyGo_Flights
bootstrap.properties
spring.cloud.config.uri=http://localhost:1111
management.endpoints.web.exposure.include
InfyGo_Flights.yml
spring:
application:
name: InfyGo_Flights
mvc:
view:
prefix: /WEB-INF/pages/
suffix: .jsp
datasource:
username: root
password:
url: jdbc:mysql://localhost:3307/mydb?serverTimezone=UTC
jpa:
show-sql: true
hibernate:
ddl-auto: update
properties:
hibernate:
dialect:
logging:
file: Errorlog.log
level:
root: info
com.infoys.ars: info
pattern:
file: "%d{yyyy-MM-dd HH:mm:ss,SSS} %5p [%t] %c [%M] - %m%n"
server:
port:9004
You will need to put a Whitespace between the port & 9004 so it get recognizable by the yaml file:
//wrong
port:9004
//right
port: 9004

Spring Boot 1.4: set default profile when deploying the app in Tomcat

I have a Spring Boot 1.4 application which has a YAML-based config file. The config file specifies a default profile: prod
spring:
profiles.active: prod
When I generate a war using Maven and deploy to Tomcat 7, the default profile is not set. Tomcat log:
No active profile set, falling back to default profiles: default
In order to set the default profile in the app deployed in Tomcat, I can pass a System property to Tomcat, like so:
-Dspring.profiles.active=prod
This works, but I would like to use the Spring Boot properties, rather than the System properties for setting a default profile.
Is there a reason why the default yaml property file is ignored when the application is deployed in Tomcat?
Just rename your profile to default and add a different name for development, like this:
spring:
profiles: development
devtools:
restart:
enabled: false
thymeleaf:
mode: HTML
cache: false
http:
multipart:
max-file-size: 3Mb
max-request-size: 4Mb
logging:
level:
org.apache: WARN
org.apache.catalina.webresources.Cache: ERROR
org.hibernate: WARN
org.hibernate.SQL: WARN
org.hibernate.type: WARN
org.hibernate.jpa.internal: ERROR
org.springframework: WARN
org.springframework.data.jpa: WARN
org.springframework.validation: WARN
org.springframework.web: WARN
org.springframework.web.socket: WARN
org.zkoss: WARN
com.ultraip: TRACE
---
spring:
profiles: default
thymeleaf:
mode: HTML
http:
multipart:
max-file-size: 3Mb
max-request-size: 4Mb
messages:
cache-seconds: -1
resources:
cache-period: 259200
server:
port: 80
session:
timeout: 86400
compression:
enabled: true
mime-types: "text/html,text/xml,text/css,text/plain,application/json,application/xml,application/javascript"
security:
headers:
cache: false
logging:
file: "/var/log/intranet.log"
level:
org.apache: WARN
org.apache.catalina.webresources.Cache: ERROR
org.hibernate: WARN
org.hibernate.jpa.internal: ERROR
org.springframework: WARN
org.zkoss: WARN
com.ultraip: INFO
The "---" denotes the start of a different config file

Resources