• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Spring mvc works with AdminDaoImpl but not if you implement the AdminDao

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can persist an admin to the database when i dont implement the interface but when i implement it, i get this error.



adminDao


AdminDaoImpl



but when i do this it works, but i dont want to to it this way i want to implement the interface


adminservice


Please can anyone help me with this, it must be a way to get it to work when implementing the interface ?
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should code your service to the interface not to the implementation. In other words, in admin service, declare ar as AdminService
 
mike molin
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i get the same problem if i code it to the adminservice, as long as i dont implement the interface it works, but as soon as i implement it i get the same error
 
Jayesh A Lalwani
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, my mistake. In AdminService, declare are as AdminDAO, not as AdminDAOImpl
 
mike molin
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much now it works :-)
But why does it work when i use the Dao and not the DaoImpl
 
Jayesh A Lalwani
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you have an AOP annotation on a class that implements an interface, spring creates a java proxy class that implements the interface. When the proxy is called, it calls the aspect and your class. If your class doesn't implement interface, spring cannot use java proxy, so it falls back to using cglib, which creates a class that extends your class. So, the differrence is when you implement interface spring creates a class that implements the interface, when you don't implement interface, spring creates a class that extends your class

Now, during auto wiring, if it has a proxy class that implements the AdminDAO interface, it cannot inject it I to a property of type admindaoimpl. Once you changed your auto wiring to inject the interface, it worked
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic