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

java.sql.SQLException -> ClassDef #964

Open
wites342 opened this Issue Jan 17, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@wites342
Copy link

wites342 commented Jan 17, 2019

While testing RestController with SpringBoot I got java.lang.NoClassDefFoundError: java/sql/SQLException. SpringBoot is configured to work with Jackson.

Environment:

  • springboot -> 2.1.2.RELEASE
  • spock -> 1.2-groovy-2.5
  • groovy -> 2.5.4
  • jackson -> 2.9.8
  • JAVA 11
  • gradle -> 5.1.1
  • Intellij Idea 2018.3.3

Controller definition

@RestController
@RequiredArgsConstructor
public class MyController {

    @GetMapping
    public MyResponse getResponse() {
        return new MyResponse();
    }
}

Controller test definition


class MyController extends Specification {

    private MyController myController = new MyController()

    private MockMvc mockMvc = MockMvcBuilders.standaloneSetup(controller)
            .setMessageConverters(jacksonMessageConverter())
            .build();

    def "should return 200 OK when GET findContractsTfiDetails"() {
        //test
    }

	private static HttpMessageConverter<?> jacksonMessageConverter() {
        MappingJackson2HttpMessageConverter messageConverter = new MappingJackson2HttpMessageConverter();
        messageConverter.setObjectMapper(new ObjectMapper()
            .registerModule(new JavaTimeModule())
            .enable(MapperFeature.DEFAULT_VIEW_INCLUSION)
            .setSerializationInclusion(JsonInclude.Include.NON_NULL));
        return messageConverter;
    }
}

EXCEPTION

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 (file:/PATH/groovy-2.5.5.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
java.lang.NoClassDefFoundError: java/sql/SQLException

	at org.springframework.core.MethodIntrospector.selectMethods(MethodIntrospector.java:72)
	at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.detectHandlerMethods(AbstractHandlerMethodMapping.java:267)
	at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.processCandidateBean(AbstractHandlerMethodMapping.java:252)
	at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:211)
	at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:199)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:164)
	at org.springframework.test.web.servlet.setup.StandaloneMockMvcBuilder.registerMvcSingletons(StandaloneMockMvcBuilder.java:382)
	at org.springframework.test.web.servlet.setup.StandaloneMockMvcBuilder.initWebAppContext(StandaloneMockMvcBuilder.java:364)
	at org.springframework.test.web.servlet.setup.AbstractMockMvcBuilder.build(AbstractMockMvcBuilder.java:132)
	at my.package.MyController.$spock_initializeFields(MyController.groovy:40)
Caused by: java.lang.ClassNotFoundException: java.sql.SQLException
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	... 11 more

@leonard84

This comment has been minimized.

Copy link
Member

leonard84 commented Jan 17, 2019

Looks like you are missing some dependency, also note that spock-1.2 does not fully support Java 11 yet, you can use the 1.3-SNAPSHOT or a jitpack build of master.
Please provide a Short, Self Contained, Correct (Compilable), Example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.