I have a passing Spock/Groovy Unit Test in a Spring5 Java application that autowires in a custom com.google.gson.Gson
bean:
@SpringBootTest(classes = [GsonConfig])
class DeserializerSpec extends Specification {
@Autowired
Gson gson
And the Config object that provides the bean is as follows:
@Configuration
public class GsonConfig {
@Bean
@ConditionalOnMissingBean
public Gson gson() {
GsonBuilder gsonBuilder = new GsonBuilder();
....
return gsonBuilder.create();
}
}
When I upgrade the application to Spring6, the gson object Autowired into the test is now null so the test fails.
I have tried adding a @ContextConfiguration
annotation to point to the Context object, but this results in java.lang.NoClassDefFoundError: org/springframework/beans/factory/config/InstantiationAwareBeanPostProcessorAdapter
How can I rewrite this test to Autowire the required bean in Spring6?