Skip to content

Instantly share code, notes, and snippets.

@tnymlr
Created September 12, 2014 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tnymlr/1144549572771a1e3f36 to your computer and use it in GitHub Desktop.
Save tnymlr/1144549572771a1e3f36 to your computer and use it in GitHub Desktop.
Spring fails to inject dependency in Java 8.
package com.jlectra;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;
import java.util.concurrent.Callable;
/**
* Hello world!
*
*/
@ComponentScan("com.jlectra")
public class App
{
@Component
public static class MyCallable implements Callable<Thread>{
@Override
public Thread call() throws Exception {
return null;
}
}
@Component
public static class SecondCallable implements Callable<Thread>{
@Override
public Thread call() throws Exception {
return null;
}
}
public static abstract class Foo<T extends Runnable, RT extends Callable<T>> {
private RT obj;
protected void setObj(RT obj) {
this.obj = obj;
}
}
@Component
public static class FooBar extends Foo<Thread, MyCallable> {
@Override
@Autowired
public void setObj(MyCallable obj) {
super.setObj(obj);
}
}
public static void main( String[] args ) throws Exception
{
ApplicationContext ctx = new AnnotationConfigApplicationContext(App.class);
FooBar bar = ctx.getBean(FooBar.class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment