8

I have two classes

public abstract class AbstractDAO<T> {
    private final MyExecutor<T> myExecutor;
    private final Class<T> clazz;

    public AbstractDAO(MyExecutor<T> myExecutor, Class<T> clazz) {
        this.myExecutor = myExecutor;
        this.clazz = clazz;
    }
}

and

@Component
public class MyDAOImpl extends AbstractDAO<Manager> {
    private final SessionManager sessionManager;
    private final MyExecutor<Manager> myExecutor;

    @Autowired
    public MyDAOImpl(SessionManager sessionManager, MyExecutor<Manager> myExecutor) {
        super(myExecutor, Manager.class);

        this.sessionManager = sessionManager;
        this.myExecutor= myExecutor;
    }
}

I got an error at the definition of the abstract class saying that: "Class doesn't contain matching constructor for autowiring".

All I did is added an additional constructor parameter to the constructor of AbstractDAO which is a Class. I need this because I didn't find a way to detect this out from T at run time (stackflow search says there isn't one).

How can I fix this? How can I pass the Class information which can only be determined in the implementation class?

Many thanks

Kevin
  • 5,972
  • 17
  • 63
  • 87
  • It is a compile time error. No stack stace. Thanks. – Kevin Feb 16 '14 at 15:44
  • You might want to read: http://stackoverflow.com/questions/3153546/how-does-autowiring-work-in-spring and http://stackoverflow.com/questions/19414734/spring-autowired-usage – pedromss Feb 16 '14 at 16:28
  • Your code, as shown, compiles fine. – Sotirios Delimanolis Feb 16 '14 at 17:26
  • It only compiles if I add a @Autowired in the constructor of the abstract class AbstractDAO. Otherwise, it won't. I want to know why it is like this. Many thanks. – Kevin Feb 16 '14 at 17:28
  • I think you are misunderstanding what compilation is. Your error is not a compilation error (unless there is something seriously missing from your question). – Sotirios Delimanolis Feb 16 '14 at 17:38
  • Hi. Thanks for your answer. You are right, this does compiles fine. But my intelliJ somehow mark this as an error if I don't put the @Autowiring before the constructor of AbstractDAO. But it does compiles fine. – Kevin Feb 16 '14 at 20:23

1 Answers1

5

This is a bug in IntelliJ that is fixed in 13.1. http://youtrack.jetbrains.com/issue/IDEA-120977

robert_difalco
  • 4,821
  • 4
  • 36
  • 58