Announcement Announcement Module
Collapse
No announcement yet.
Autowiring Class Issue (argument type mismatch) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Autowiring Class Issue (argument type mismatch)

    I have a Interface:
    Code:
    public interface IGenericDAO
    and a implementing abstract class:
    Code:
    @Repository
    public abstract class  GenericDAOImpl implements IGenericDAO
    Then there are class that extends the abstract class like:
    Code:
    @Repository
    public class ClientDAO extends GenericDAOImpl
    When i try to autowire ClientDAO into serverice as below:
    Code:
    @Component
    public class ClientServiceImpl implements ClientService{
    	private ClientDAO clientDAO;
    	@Autowired
    	public void setClientDAO(Object clientDAO) {
    		this.clientDAO = clientDAO;
    	}
    It throws exception below:
    Code:
    Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: 
    public void com.xxx.service.impl.ClientServiceImpl.setClientDao(com.xxx.dao.ClientDAO); 
    nested exception is java.lang.IllegalArgumentException: argument type mismatch

  • #2
    Just get it fixed. I aspect applied as:
    <aop:aspectj-autoproxy/>

    therefore marking it as :
    <aop:aspectj-autoproxy proxy-target-class = "true"/>

    fixes the issue.

    Comment


    • #3
      You don't have to force classproxies to resolve this issue.
      Just use proper javabean setter specification (make the setter argument match the return type):

      Code:
      private ClientDAO clientDAO;
      	@Autowired
      	public void setClientDAO(ClientDAO clientDAO) {
      		this.clientDAO = clientDAO;
      	}
      or get rid of the setter altogether and autowire directly on the class variable:

      Code:
      @Autowired
      private ClientDAO clientDAO;

      Comment


      • #4
        I removed all setters and put @Autowired on variables. However this doesn't solve issue until class proxies are applied.

        Comment

        Working...
        X