Error creating mongock bean when deploying on docker - spring-boot

I am using Mongck to migrate data in my Spring Boot application. Spring Boot application runs perfectly locally. But when running on docker, the following error occurs:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongockInitializingBeanRunner' defined in class path resource [vn/vnpt/icode/svc/config/config/MongockConfig.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/data/mongodb/MongoDatabaseFactory
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796) ~[spring-beans-5.2.2.RELEASE.jar!/:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.2.RELEASE.jar!/:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.2.RELEASE.jar!/:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.2.RELEASE.jar!/:5.2.2.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.2.RELEASE.jar!/:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.2.RELEASE.jar!/:5.2.2.RELEASE]
see the full logs here
Here is the dependencies in build.gradle file:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-cache'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'javax.xml.bind:jaxb-api'
implementation 'com.github.cloudyrock.mongock:mongock-bom:4.3.7'
implementation 'com.github.cloudyrock.mongock:mongodb-springdata-v3-driver:4.3.7'
implementation 'com.github.cloudyrock.mongock:mongock-spring-v5:4.3.7'
implementation 'com.hazelcast:hazelcast-kubernetes:2.0'
implementation 'com.hazelcast:hazelcast-spring'
implementation 'org.springframework.cloud:spring-cloud-starter-stream-kafka:3.0.1.RELEASE'
// implementation 'org.apache.poi:poi-ooxml:4.1.1'
implementation 'org.apache.commons:commons-collections4:4.1'
implementation 'com.google.code.gson:gson'
implementation 'org.json:json:20201115'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
and the content of MongockConfig class:
#Bean
public MongockSpring5.MongockInitializingBeanRunner mongockInitializingBeanRunner(ApplicationContext springContext, MongoTemplate mongoTemplate) {
boolean migrationsEnabled = mongoEnabled;
return MongockSpring5.builder()
.setDriver(SpringDataMongoV3Driver.withDefaultLock(mongoTemplate))
.addChangeLogsScanPackages(List.of(changeLogsScanPackage))
.setSpringContext(springContext)
.setEnabled(migrationsEnabled)
.buildInitializingBeanRunner();
}
I don't understand why it doesn't work when run on docker. Is my mongockInitializingBeanRunner method incorrect.
Someone please help me

As discussed in this Github issue, the issue was resolved by upgrading to version 4.3.7.

Related

Could not find org.projectlombok:lombok:1.18.22. error (lombok)

I've installed the lombok plugin from marketplace and enabled it.
I've also enabled annotations processor.
Here are the list of dependencies that I find in my build.gradle file :
dependencies {
implementation 'org.projectlombok:lombok:1.18.22'
implementation 'org.projectlombok:lombok:1.18.22'
implementation 'org.projectlombok:lombok:1.18.22'
implementation 'org.projectlombok:lombok:1.18.22'
implementation 'org.projectlombok:lombok:1.18.22'
implementation 'org.projectlombok:lombok:1.18.22'
implementation 'org.projectlombok:lombok:1.18.22'
implementation 'org.projectlombok:lombok:1.18.22'
implementation 'org.projectlombok:lombok:1.18.22'
implementation 'org.projectlombok:lombok:1.18.22'
implementation 'org.projectlombok:lombok:1.18.22'
implementation 'org.projectlombok:lombok:1.18.22'
implementation 'org.projectlombok:lombok:1.18.22'
}
Also this one -
buildscript {
apply plugin: 'brazil-gradle'
dependencies {
classpath brazilGradle.tool('BrazilGradleQualityDefaults')
}
I've defined #Builder annotation on a class an I find - Cannot resolve symbol 'Builder' . When I clicked on - Add lombok to class path. I'm getting the following error -
Could not find org.projectlombok:lombok:1.18.22.
Required by:
project :
Am I missing on something? Any help would be really appreciated.

beans.factory.UnsatisfiedDependencyException: Error creating bean with name

Errors for repository and service:
Error creating bean with name 'rimeService' defined in file [...]: Unsatisfied dependency expressed through constructor parameter 0;
nested exception is java.lang.NoClassDefFoundError: kotlin/reflect/full/KClasses
Error creating bean with name 'rimeRepository': Invocation of init method failed;
nested exception is java.lang.NoClassDefFoundError: kotlin/reflect/full/KClasses
RimeService:
#Service
class RimeService(private val repository: RimeRepository) {
fun findRimes(character: String) = repository.findByCharactersContains(character)
}
RimeRepository:
#Repository
interface RimeRepository: JpaRepository<Rime, Int> {
fun findByCharactersContains(character: String): List<Rime>
}
Controller:
#Controller
#RequestMapping("/rimes")
class RimeController(private val service: RimeService) {
#GetMapping("/{character}")
fun getByCharacter(#PathVariable character: String) = service.findRimes(character)
}
dependencies:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
// implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'mysql:mysql-connector-java'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'org.springframework.security:spring-security-test'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
}
In addition, the class and methods in controller is grayed out in Intelij, which means those are never used.
Please let me know if there's anything wrong with my configuration.
Thank you.

UnsatisfiedDependencyException for #DataNeo4jTest

I try to test my code with Spring-Boot Neo4j but I've got an error like org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.sha.neo4j.service.UserServiceTest': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.sha.neo4j.service.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
Dependencies;
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-neo4j'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'org.neo4j.test:neo4j-harness:4.0.0'
testImplementation 'org.neo4j:neo4j-ogm-embedded-driver:3.2.8'
}
And test class;
#RunWith(SpringRunner.class)
#DataNeo4jTest
public class UserServiceTest
{
#Autowired
private UserService userService;
#Test
public void testIt()
{
User user = new User();
user.setLastName("Test");
user.setName("Test");
userService.saveUser(user);
List<User> users = userService.findAll();
assertThat(users).hasSize(1);
}
}
In here, I've jus try to test above code with embedded driver but I've got an error like above. I don't have a specific properties (test application.properties) for test. Test works with neo4j-desktop bolt driver.
Is there any suggestion?
You should use #SpringBootTest over your tests. #DataNeo4jTest doesn't load any required services.

Spring boot Eureka server project not starting

I just created Spring Boot project(with Gradle Buildship 3.x) and I enabled Eurekaserver on main class.I am getting following error
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'traceFilterRegistration' defined in class path resource [org/springframework/cloud/netflix/eureka/server/EurekaServerAutoConfiguration.class]: Unsatisfied dependency expressed through method 'traceFilterRegistration' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.servlet.Filter' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {#org.springframework.beans.factory.annotation.Qualifier(value=httpTraceFilter)}
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:798) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:539) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
build.gradle:
plugins {
id 'org.springframework.boot' version '2.2.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
implementation('org.springframework.boot:spring-boot-starter-actuator')
implementation('org.springframework.boot:spring-boot-starter-web')
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-netflix-eureka-server', version: '2.0.1.RELEASE'
}
test {
useJUnitPlatform()
}
application.properties:
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.service-url.defaultZone=http://localhost:8761/eureka
Issue that you encounter has been fix already, at May 13 2019, issue
spring-cloud-netflix
Though issue has been resolved over a year ago I encounter it lately. For reference, as workaround, you can add missing bean. It will be created only if not provided by spring cloud netfix:
#ConditionalOnMissingBean
#Bean
public HttpTraceRepository httpTraceRepository() {
return new InMemoryHttpTraceRepository();
}

java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration

I am trying to write a standalone executable jar (fat jar) . I am using spring boot gradle plugin and writing a SpringBoot App to do this.
Here is my Application.java file
#Configuration
#EnableAutoConfiguration
#EnableRabbit
#EntityScan("persistence.domain")
#EnableJpaRepositories("persistence.repository")
#ComponentScan(basePackages = {"common","service"})
public class Application {
public static void main(final String[] args) {
final SpringApplicationBuilder appBuilder = new SpringApplicationBuilder(
Application.class);
appBuilder.profiles("common", "common_db").run(args);
}
#Bean
#Primary
#ConfigurationProperties(prefix = "spring.datasource")
public DataSource primaryDataSource() {
return DataSourceBuilder.create().build();
}
}
I have specified properties in yml files. For ex application-common etc . While running Application.java I am getting error :
[2015-09-24 14:40:22.304] boot - 32791 INFO [main] ---AnnotationConfigEmbeddedWebApplicationContext: Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#51a282af: startup date [Thu Sep 24 14:40:22 IST 2015]; root of context hierarchy
[2015-09-24 14:40:23.194] boot - 32791 WARN [main] --- AnnotationConfigEmbeddedWebApplicationContext: Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load bean class: ; nested exception is java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration
at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:392)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:165)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:305)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:611)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:142)
at storm.Application.main(Application.java:28)
Caused by: java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:58)
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:92)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:190)
at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:435)
at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:389)
... 12 more
Caused by: java.lang.NullPointerException
at org.springframework.boot.autoconfigure.condition.OnPropertyCondition.getMatchOutcome(OnPropertyCondition.java:61)
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:45)
... 16 more
Here is my build.gradle
def projects= [
":common",
":persistence",
":adapter"
]
buildscript {
repositories {
mavenCentral()
maven { url 'http://repo.spring.io/snapshot' }
maven { url 'http://repo.spring.io/milestone' }
}
dependencies { classpath group: 'org.springframework.boot', name: 'spring-boot-gradle-plugin', version: springBootVersion }
}
apply plugin: 'spring-boot'
apply plugin: 'maven-publish'
apply from: "${rootDir}/deployTasks.gradle"
springBoot {
mainClass = "storm.Application"
}
dependencies {
compile project(':common')
compile project(':adapter')
compile project(':persistence')
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: '1.1.8.RELEASE'
compile group : 'org.springframework.boot',name: 'spring-boot-autoconfigure', version : '1.1.8.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '1.1.8.RELEASE'
}
Database specification as in application-common_db.yml
database:
host: localhost
port: 3306
schema: subscriptions
username: root
password: root
autoconnect:
maxReconnects: 3
initialTimeout: 2
timeout:
connectTimeout: 0
socketTimeout: 0
failover:
host: localhost
port: 3306
queriesBeforeRetryMaster: 50
secondsBeforeRetryMaster: 30
spring:
datasource:
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://${database.host}:${database.port},${database.failover.host}:${database.failover.port}/${database.schema}?${database.properties}
username: ${database.username}
password: ${database.password}
continueOnError: true
initialize: false
initialSize: 0
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 5000
removeAbandonedTimeout: 60
removeAbandoned: true
minIdle: 0
I am not sure how to resolve this error . Can nybody suggest what is going wrong here and why am i getting nullPointerException.
Help is appreciated .
Thanks
This is caused by non-matching Spring Boot dependencies. Check your classpath to find the offending resources. You have explicitly included version 1.1.8.RELEASE, but you have also included 3 other projects. Those likely contain different Spring Boot versions, leading to this error.
I know this is quite an old one, but I faced similar issue and resolved it in a different way. The actuator-autoconfigure pom somehow was invalid and so it was throwing IllegalStateException. I removed the actuator* dependencies from my maven repo and did a Maven update in eclipse, which then downloaded the correct/valid dependencies and resolved my issue.
In my case I had created a SB app from the SB Initializer and had included a fair number of deps in it to other things. I went in and commented out the refs to them in the build.gradle file and so was left with:
implementation 'org.springframework.boot:spring-boot-starter-hateoas'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'org.hsqldb:hsqldb'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
as deps. Then my bare-bones SB app was able to build and get running successfully. As I go to try to do things that may need those commented-out libs I will add them back and see what breaks.
This error is because of multiple projects having the offending resources.
Try out adding the dependencies projects another way around. (like in pom.xml or external dependencies)
I had the same its because of hibernate-core version issue when you remove the version so it resolve the problem you should try it.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.4.Final</version>
</dependency>
If it's a new project, make sure you remembered to add spring starter web dependency
I had the same its because of version incompatibility check for version or remove version if using spring boot

Resources