Results 1 to 5 of 5

Thread: @autowired pblm

  1. #1
    Join Date
    Dec 2007
    Location
    Kerala, India
    Posts
    66

    Unhappy @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
    Nidhin

  2. #2
    Join Date
    Jul 2005
    Location
    Geneva (Switzerland)
    Posts
    304

    Default

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

  3. #3
    Join Date
    Dec 2007
    Location
    Kerala, India
    Posts
    66

    Default

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

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    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?
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Dec 2007
    Location
    Kerala, India
    Posts
    66

    Default

    ok thanks for your valuable post
    Nidhin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •