JobRunr with Spring Boot - ConverterNotFound Exception - java

I have a Kotlin Spring Boot application and tried to integrate the JobRunr Spring Boot Starter dependency, along with the Kotlin JobRunr Support Module. Dependencies:
// Jackson JSON Serialization
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.13.3")
// Spring Boot Version is 2.7.1 (latest)
// Jobs
implementation("org.jobrunr:jobrunr-spring-boot-starter:5.1.6")
implementation("org.jobrunr:jobrunr-kotlin-1.7-support:5.1.6")
I configured JobRunr like this:
#Configuration
class JobRunrConfiguration {
#Bean
fun jobMapper(): JobMapper {
return JobMapper(JacksonJsonMapper(jacksonObjectMapper()))
}
}
I'm using Postgres as my database.
Application properties are as follows:
# JobRunr
org.jobrunr.background_job_server=true
org.jobrunr.dashboard=true
It is quite basic stuff after following the documentation, but when I try to start the application I get the error:
Failed to bind properties under 'org.jobrunr.background-job-server' to
org.jobrunr.spring.autoconfigure.JobRunrProperties$BackgroundJobServer".
Reason: org.springframework.core.convert.ConverterNotFoundException:
No converter found capable of converting from type [java.lang.String]
to type
[org.jobrunr.spring.autoconfigure.JobRunrProperties$BackgroundJobServer]
I tried different object mappers and configurations, swapping out dependencies, but nothing is working. Anyone have some pointers or ideas in the right direction?

It fails to parse the configuration below:
# JobRunr
org.jobrunr.background_job_server=true
org.jobrunr.dashboard=true
according to the source code the configuration should look like:
org.jobrunr.background-job-server.enabled=true
org.jobrunr.dashboard.enabled=true

Related

Quarkus Consul Config: how to inject application.yaml file from Consul Agent?

I am using Quarkus inside a microservice Java application.
I recently started to migrate from Spring Boot to Quarkus itself.
I am having some trouble while migrating "Spring Cloud Consul" to "Quarkus Consul Config". In order to be more specific, I am getting the following error:
java.lang.RuntimeException: Key 'my/consul/path/application.yaml' not found in Consul
at io.quarkus.consul.config.runtime.ConsulConfigSourceProvider$1.accept(ConsulConfigSourceProvider.java:66)
at io.quarkus.consul.config.runtime.ConsulConfigSourceProvider$1.accept(ConsulConfigSourceProvider.java:56)
at io.smallrye.context.impl.wrappers.SlowContextualConsumer.accept(SlowContextualConsumer.java:21)
at io.smallrye.mutiny.operators.uni.UniOnItemConsume$UniOnItemComsumeProcessor.invokeEventHandler(UniOnItemConsume.java:77)
at io.smallrye.mutiny.operators.uni.UniOnItemConsume$UniOnItemComsumeProcessor.onItem(UniOnItemConsume.java:42)
at io.smallrye.mutiny.operators.uni.UniOnItemTransform$UniOnItemTransformProcessor.onItem(UniOnItemTransform.java:43)
at io.smallrye.mutiny.vertx.AsyncResultUni.lambda$subscribe$1(AsyncResultUni.java:35)
(...)
Inside my Consul instance, the key my/consul/path/application.yaml corresponds to an application.yaml external file that I would like to import from there during the startup phase.
Below you can find my consul config (application.yaml):
quarkus:
application:
name: myapplication
consul-config:
enabled: true
properties-value-keys: my/consul/path/application.yaml
agent:
host-port: http://localhost:9500
prefix: myappprefix
If I try to switch from properties-value-keys to properties-raw-value-keys, I see that my property is not being injected inside my application context:
#ConfigProperty(name = "consultest")
String test;
java.util.NoSuchElementException: SRCFG00014: The config property consultest is required but it could not be found in any config source
Below you can find the application.yaml content (located on Consul):
consultest: testtest
The intent, here, is to delegate application.yaml properties to Consul, divided by environment (dev, test, prod).
I would like to threat my local application.yaml file (located in src/main/resources) as a bootstrap.yaml file, similarly to Spring Boot approach.
How could this be done with Quarkus? Thank you a lot for your support.

import com.mongodb.client.MongoClient; is not present error seen in java spring boot project

I am using spring parent version 2.4.5 and spring mongodb data module 3.1.8 version and this module internally uses 'mongodb-driver-core version 4.1.2' which seems to be the java mongo driver version being used by the dependency. My problem is I am trying to connect to mongo db cluster on my local using the latest spring boot version and my project uses maven but my intelliJ and eclipse(tried in both) shows import com.mongodb.client.MongoClient; as red meaning both the IDEs are not able to detect this class and find it.
Sharing Code snippet (for giving an idea where the error is) that I am using to create the mongotemplate bean
#Bean public MongoClientFactoryBean getMongoFactoryBean(){ return new MongoClientFactoryBean();}
#Bean public MongoTemplate getTemplate(MongoClientFactoryBean factory){ return new MongoTemplate(factory.getObject(), "some database name")}
I get an error in above method while doing a build java cannot access com.mongodb.client.MongoClient class file for com.mongodb.client.MongoClient not found
Any Idea what is going wrong here and any suggestions to solve this issue?

Failed to ugrade a Spring Boot app to Flyway 7.0.0

I'm trying to upgrade my Spring Boot 2.3.4 app to use Flyway 7.0.0 (the latest version). Previously it was using Flyway 6.5.6. The relevant entries in build.gradle are shown below.
buildscript {
ext {
flywayVersion = "7.0.0" // changed from 6.5.6
}
}
plugins {
id "org.flywaydb.flyway" version "${flywayVersion}"
}
dependencies {
implementation "org.flywaydb:flyway-core:${flywayVersion}"
}
flyway {
url = "jdbc:postgresql://0.0.0.0:5432/postgres"
user = "postgres"
password = "secret"
}
The following error occurs when I start the app e.g. with ./gradlew bootRun
APPLICATION FAILED TO START
Description:
An attempt was made to call a method that does not exist. The attempt
was made from the following location:
org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:65)
The following method did not exist:
'int org.flywaydb.core.Flyway.migrate()'
The method's class, org.flywaydb.core.Flyway, is available from the
following locations:
jar:file:/Users/antonio/.gradle/caches/modules-2/files-2.1/org.flywaydb/flyway-core/7.0.0/623494c303c62080ca1bc5886098ee65d1a5528a/flyway-core-7.0.0.jar!/org/flywaydb/core/Flyway.class
The class hierarchy was loaded from the following locations:
org.flywaydb.core.Flyway: file:/Users/antonio/.gradle/caches/modules-2/files-2.1/org.flywaydb/flyway-core/7.0.0/623494c303c62080ca1bc5886098ee65d1a5528a/flyway-core-7.0.0.jar
Action:
Correct the classpath of your application so that it contains a
single, compatible version of org.flywaydb.core.Flyway
Basically, see Philip's comment on your question.
Flyway 7.x.x is not currently compatible with Spring Boot 2.3.4
Temporary solution is to just downgrade to Flyway 6.5.7 (the last 6.x.x version) until Spring Boot 2.3.5 is released.
Read more and follow the issue here: https://github.com/spring-projects/spring-boot/issues/23514
Support for Flyway's new configuration options: https://github.com/spring-projects/spring-boot/issues/23579
In Flyway 7 the signature of migrate changed.
To get Flyway 7.x.x working with Spring Boot 2.3.x you can provide a custom FlywayMigrationStrategy implementation, which calls the the right migrate method.
import org.flywaydb.core.Flyway;
import org.springframework.boot.autoconfigure.flyway.FlywayMigrationStrategy;
import org.springframework.stereotype.Component;
#Component
public class FlywayMigrationStrategyImpl implements FlywayMigrationStrategy {
#Override
public void migrate(Flyway flyway) {
flyway.migrate();
}
}
downgrade to Flyway 6.5.7 works.

SpringBoot 2 with Flyway: spring.flyway.locations is ignored

I am using Spring Boot 2.2.2 with Flyway 5.2.4 and I tried to configure flyway to use a differente location for the scripts, but spring.flyway.locations=filesystem:db_other/migration/{vendor} neither flyway.locations=filesystem:db_other/migration/{vendor} configurations on application.properties worked.
When running the program, the following exception appear in the log:
FlywayMigrationScriptMissingException: Cannot find migration scripts in: [classpath:db/migration]
I already tried using Spring Boot 2.2.1, 2.2.0, 2.1.11 and Flyway 6.1.0 and 6.1.3, but the result is the same.
The default value for that property is classpath:db/migration as shown here (search for flyway).
Since you're using a different folder in the resources directory you should only need to change "filesystem" to "classpath" in your application.properties value.
Actually if was my fault: as I used to work with just spring (not spring boot) I configured my test class with the annotations #ExtendWith(SpringExtension.class) AND #ContextConfiguration(classes = { MyConfiguration.class }) instead of just use #SpringBootTest. When making this change the test worked.

Multiple annotations found at this line: Factory bean not Found

I am building a Spring project in Spring Tool Suite(3.6.4.RELEASE).
I am trying to upgrade spring framework version from 4.0.3.RELEASE to 4.2.7.RELEASE using maven.
Before upgradation there was no error and everything running smoothly. Now project is compiling and running without error but login page is not showing and also I am getting error in my spring security configuration xml.
Error in spring-security.xml:
Showing following error on STS hovering:
Multiple annotations found at this line:
- Factory bean 'org.springframework.security.config.http.FilterInvocationSecurityMetadataSourceParser
$DefaultWebSecurityExpressionHandlerBeanFactory' not found [config set: mcare-dashboard-web/web-context]
- Factory bean 'org.springframework.security.config.http.HttpConfigurationBuilder
$SecurityContextHolderAwareRequestFilterBeanFactory' not found [config set: mcare-dashboard-web/web-context]
Project Hierarchy:
My pom.xml was like following:
Then I just changed the version number like this:
After that spring-security.xml was showing the error.
Can anybody explain why is this happening?
You state that you are upgrading Spring from version 4.0.3.RELEASE to 4.2.7.RELEASE. However effectively you are upgrading both Spring and Spring Security. This due to having a single version property, named org.springframework-version, to manage both the version of the Spring and Spring Security dependencies.
So changing org.springframework-version to 4.2.7.RELEASE effectively upgrades Spring Security as well.
To fix this you want to have two distinct version properties one for Spring and another for Spring Security. You can than upgrade only Spring or Spring Security.

Categories

Resources