Created
September 12, 2014 14:22
-
-
Save tnymlr/1144549572771a1e3f36 to your computer and use it in GitHub Desktop.
Spring fails to inject dependency in Java 8.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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