Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonUnit 4.0.0: causes java.lang.ClassNotFoundException: org.springframework.beans.factory.BeanFactoryInitializer #855

Open
pstorch opened this issue Nov 19, 2024 · 17 comments

Comments

@pstorch
Copy link

pstorch commented Nov 19, 2024

Describe the bug

  1. Describe which variant of the API are you using (AssertJ, Hamcrest, ...)
    AssertJ, SpringMVC
  2. Create a small reproducible example and paste it the bug report.
    tbd. (Need some time to create this)
  3. Describe expected behavior

Until json-unit 3.5.0 all tests did run fine, since 4.0.0 I get the following Exception in my Spring Tests:

Caused by: java.lang.NoClassDefFoundError: org/springframework/beans/factory/BeanFactoryInitializer
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1027)
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
	at org.springframework.test.context.support.DynamicPropertiesContextCustomizer.customizeContext(DynamicPropertiesContextCustomizer.java:70)
	at org.springframework.boot.test.context.SpringBootContextLoader$ContextCustomizerAdapter.initialize(SpringBootContextLoader.java:443)
	at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:627)
	at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:401)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:334)
	... 28 more

Using Spring Boot 3.3.5.

@jpgoelz

This comment has been minimized.

@lukas-krecan
Copy link
Owner

JsonUnit is dependent on Spring 6.2 so maybe it's pulling a newer version of a Spring module. It should not happen if you are using Spring Boot BOM. Can you check the Spring versions resolved by your build tool?

@lukas-krecan
Copy link
Owner

Btw. JsonUnit should work with older version of Spring, so you can force older version

@jpgoelz

This comment has been minimized.

@lukas-krecan
Copy link
Owner

What's you spring-test version?

@pstorch
Copy link
Author

pstorch commented Nov 20, 2024

This is when 3.4.1 is used:
Screenshot 2024-11-20 at 07 56 32

And this is with 4.0.0:

Screenshot 2024-11-20 at 07 57 42

@lukas-krecan
Copy link
Owner

Yes, JsonUnit pulled in a newer version of spring-test. In this case you have to explicitly set the same version as the rest of spring dependencies in your Maven or Gradle file (or use Spring Boot BOM that does it for you)

@pstorch
Copy link
Author

pstorch commented Nov 20, 2024

@lukas-krecan thanks

I already use the spring Boot BOM:

dependencies {
    implementation(platform(SpringBootPlugin.BOM_COORDINATES))
...

But I had to explicitly exclude the spring-test dependency from json-unit:

    testImplementation(libs.json.unit.spring) {
        // https://github.com/lukas-krecan/JsonUnit/issues/855
        exclude(group = "org.springframework", module = "spring-test")
    }

This solved it for me.

@jpgoelz

This comment has been minimized.

@lukas-krecan
Copy link
Owner

@jpgoelz Hi, can you please share what exception are you seeing? Is it really the same as the one reported here?

@jpgoelz

This comment has been minimized.

@lukas-krecan

This comment has been minimized.

@jpgoelz

This comment has been minimized.

@lukas-krecan
Copy link
Owner

You have to upgrade Jackson to at least 2.14

@pstorch
Copy link
Author

pstorch commented Nov 22, 2024

We got the Spring Boot 3.4.0 update today. Now my fix from #855 (comment) is not needed anymore.

From my point of view this ticket can be closed.

@jpgoelz

This comment has been minimized.

@lukas-krecan
Copy link
Owner

Let's keep it open for a while, so others have an easier time finding it. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants