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

bug in spring-boot because classloader #97

Open
mvpcortes opened this issue Aug 5, 2017 · 3 comments
Open

bug in spring-boot because classloader #97

mvpcortes opened this issue Aug 5, 2017 · 3 comments

Comments

@mvpcortes
Copy link

mvpcortes commented Aug 5, 2017

Hi,

I am use fixture-factory with spring-boot. I need create fixtures for fake some objects.

When I use Fixture.from(MyClass.class).gimme("valid"); the MyClass.class return a class from RestartClassLoader. But the fixture-factory load my fixture using other classloader (Launcher$AppClassLoader).

I think this generate two diff MyClass classes and my application fail to identify they in Map "template" inside of Fixture class.

There is something I can do to avoid this error?

Thanks.

@mvpcortes
Copy link
Author

I create a project-example: https://github.com/marcosvpcortes/fixture-factory-spring-boot-error

I'm using spring-boot-devtools. Without it the project will works... I think it is a minor error

I will try create a fix.... The better way is not use the class to key of the template map? I could use the name of class?

Thanks...

@gregjones60
Copy link

Did you ever get this resolved? I had the same issue today but worked around it by providing my own implementation of FixtureFactory.loadTemplate(String packageName), using the Reflections library (https://github.com/ronmamo/reflections):

`
public void loadTemplates(String basePackage) {
Iterator i$ = getClassesForPackage(basePackage).iterator();

    while(i$.hasNext()) {
        Class<?> clazz = (Class)i$.next();
        if (!clazz.isInterface() && TemplateLoader.class.isAssignableFrom(clazz)) {
            try {
                ((TemplateLoader)clazz.newInstance()).load();
            } catch (Exception var4) {
                throw new RuntimeException(String.format("template %s not loaded", clazz.getName()), var4);
            }
        }
    }

}

public Set<Class<? extends BaseBlueprint>> getClassesForPackage(String packageName) {
    Reflections reflections = new Reflections(packageName);

    return reflections.getSubTypesOf(BaseBlueprint.class);
}

`

There is a bug in the getClassesForPackage utility method that the FixtureFactory uses to find the classes in a package, because of the nested jar files in a spring boot packaged jar. I'm not sure what the Reflections package does differently but it works OK.

@mvpcortes
Copy link
Author

Hello @gregjones60

A can not solve the problem. Thanks by your solution.

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

2 participants