Announcement Announcement Module
Collapse
No announcement yet.
How to define a Spring bean using annotation instead of XML? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to define a Spring bean using annotation instead of XML?

    <bean id="bootstrap" class="com.package.Bootstrap"></bean>

    this works fine. The bootsrap class :

    public class Bootstrap {

    @PostConstruct
    public void onServerStart() {
    System.out.println("PRINTSSSSSSSSSSSSSSSSSSS");
    }
    }

    }


    The method gets fired.

    But how can I get rid of the xml part, and annotate bootstrap to be a bean instead?

    I have

    <mvc:annotation-driven />
    <context:annotation-config />


    and

    <context:component-scan base-package="com.package" />


    But I was wondering what the annotation used should be.

    I could not find anything about this online and in the spring docs...

  • #2
    Hello

    Next time use code tags

    Read carefully the follow

    4.9 Annotation-based container configuration
    4.10 Classpath scanning and managed components

    Comment

    Working...
    X