From 67387472fb76fab1d20231f07048ee15897d58e7 Mon Sep 17 00:00:00 2001 From: cliedeman Date: Tue, 22 Nov 2016 14:28:10 +0200 Subject: [PATCH] Changed AnnotationUtils work with executable spring boot jars --- .../graphql/utils/AnnotationUtils.java | 7 ++++--- .../graphql/utils/AnnotationUtilsTest.java | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 src/test/java/com/bretpatterson/schemagen/graphql/utils/AnnotationUtilsTest.java diff --git a/src/main/java/com/bretpatterson/schemagen/graphql/utils/AnnotationUtils.java b/src/main/java/com/bretpatterson/schemagen/graphql/utils/AnnotationUtils.java index 24d9d5b..cbf79bd 100644 --- a/src/main/java/com/bretpatterson/schemagen/graphql/utils/AnnotationUtils.java +++ b/src/main/java/com/bretpatterson/schemagen/graphql/utils/AnnotationUtils.java @@ -17,7 +17,7 @@ import java.util.Map; /** - * Common Annotaiton related utility methods. + * Common Annotation related utility methods. */ public class AnnotationUtils { @@ -27,10 +27,11 @@ public class AnnotationUtils { private static ClassPath classPath; public final static class DEFAULT_NULL_CLASS extends DefaultMethodDataFetcher {} - static { try { - classLoader = AnnotationUtils.class.getClassLoader(); + // Change classloader to work with spring boot executable jars + // http://docs.spring.io/spring-boot/docs/current/reference/html/executable-jar.html#executable-jar-system-classloader + classLoader = Thread.currentThread().getContextClassLoader(); classPath = ClassPath.from(classLoader); } catch (IOException ex) { Throwables.propagate(ex); diff --git a/src/test/java/com/bretpatterson/schemagen/graphql/utils/AnnotationUtilsTest.java b/src/test/java/com/bretpatterson/schemagen/graphql/utils/AnnotationUtilsTest.java new file mode 100644 index 0000000..1e85dfe --- /dev/null +++ b/src/test/java/com/bretpatterson/schemagen/graphql/utils/AnnotationUtilsTest.java @@ -0,0 +1,20 @@ +package com.bretpatterson.schemagen.graphql.utils; + +import com.bretpatterson.schemagen.graphql.annotations.GraphQLTypeMapper; +import org.junit.Test; + +import java.util.Map; + +import static org.junit.Assert.*; + +public class AnnotationUtilsTest { + + @Test + public void getClassesWithAnnotation() throws Exception { + Map, GraphQLTypeMapper> classes = AnnotationUtils.getClassesWithAnnotation( + GraphQLTypeMapper.class, "com.bretpatterson.schemagen"); + + assertFalse(classes.isEmpty()); + } + +} \ No newline at end of file