Announcement Announcement Module
Collapse
No announcement yet.
@autowired pblm Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @autowired pblm

    Hi
    friends

    i have a controller
    Code:
    @Controller
    
    public class TestController {
        
        private final Registration registration;
        @Autowired()
        public TestController(Registration registration) {
            this.registration = registration;
        }
    and registration interface
    Code:
    public interface Registration {
        
        public int register(String name, String password, String displayname, String email) throws DataAccessException;
    and it is implimented in RegistrationImpl

    and when i run the application i got following exception

    org.springframework.beans.factory.UnsatisfiedDepen dencyException: Error creating bean with name 'testController' defined in ServletContext resource [/WEB-INF/image-servlet.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.samples.imagedb.Registration]: No unique bean of type [org.springframework.samples.imagedb.Registration] is defined: Unsatisfied dependency of type [interface org.springframework.samples.imagedb.Registration]: expected at least 1 matching bean
    org.springframework.beans.factory.support.Construc torResolver.createArgumentArray(ConstructorResolve r.java:543)
    org.springframework.beans.factory.support.Construc torResolver.autowireConstructor(ConstructorResolve r.java:178)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.autowireConstructor(Abs tractAutowireCapableBeanFactory.java:957)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBeanInstance(Abst ractAutowireCapableBeanFactory.java:869)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:514)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:485)
    java.security.AccessController.doPrivileged(Native Method)

    what is my pblm plz help

    adv thanks

  • #2
    It seems that you havent defined any bean of type Registration. Could you please post your appliationContext as well ?

    Comment


    • #3
      by using @autowired and @controller annotations i think that their is no need for configration

      Comment


      • #4
        Just using @Autowired and @Controller isn't enough. You still need an implementation of your Registration interface and that implementation has to be marked with the @Component or @Service annotation.

        How else should your application know what to inject, should it create an implementation of Register interface dynamically?

        Comment


        • #5
          ok thanks for your valuable post

          Comment

          Working...
          X