Skip to content

Commit

Permalink
Changed AnnotationUtils work with executable spring boot jars
Browse files Browse the repository at this point in the history
  • Loading branch information
cliedeman committed Dec 13, 2016
1 parent f8cc563 commit 6738747
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.util.Map;

/**
* Common Annotaiton related utility methods.
* Common Annotation related utility methods.
*/
public class AnnotationUtils {

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Class<?>, GraphQLTypeMapper> classes = AnnotationUtils.getClassesWithAnnotation(
GraphQLTypeMapper.class, "com.bretpatterson.schemagen");

assertFalse(classes.isEmpty());
}

}

0 comments on commit 6738747

Please sign in to comment.