Results 1 to 2 of 2

Thread: @Bean is not working

  1. #1
    Join Date
    Mar 2008
    Posts
    23

    Default @Bean is not working

    Hi,

    I am using @Bean annotation within class annotated with @Component

    @Component
    public class ClassWithComponentAnnotation {

    @Bean
    @Qualifier("classCreatedWithInComponentAnnotatedCl ass")
    public ClassCreatedWithInComponentAnnotatedClass publicInstance() {
    return new ClassCreatedWithInComponentAnnotatedClass();
    }
    }
    -------------------------------------------------------------------------------
    Now when i some other class i am doing like below then it is giving me error that bean not found...

    ClassCreatedWithInComponentAnnotatedClass classCreatedWithInComponentAnnotatedClass = applicationContext.getBean("classCreatedWithInComp onentAnnotatedClass", ClassCreatedWithInComponentAnnotatedClass.class);

    Can you please suggest that what i am doing wrong with,,,,,

    Thanks

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Please use [ code][/code ] tags when posting code that way it remains readable [ code][/code ]

    A (@)Qualifier isn't a bean name... If you want to change the name either change the method name or simply set the name property on the Bean annotation.
    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

Posting Permissions

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