Announcement Announcement Module
No announcement yet.
Spring MVC related - Mapping using @Controller. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring MVC related - Mapping using @Controller.

    I am using @Controller to design my system. I have defined a Controller class, a BO class and a DAO Class.
    My question is, in my applicationContext.xml file, where will I define the BO and DAO class, or would I have to define the BO and DAO beans in the xml file at all.
    Since with @controller annotation, I am no longer required to define my controller bean in the xml. Even though I use @Autowired annotation, it will only inject the dependencies based on the Type of name of the dependent beans, which mean I would need to define them somewhere.

    can I only define the bean IDs corresponding to BO and DAO classes and not define the Controller bean in the xml file, and leave it upto the Spring to take care of all the dependencies.

    Or Do I have to use @Autowired in my BO class as well. What are my choices.

    Here are my classes.

    class Controller{
    private XYZBO xyxBO;
    class XYXBO {
    Private XYZDAO xyzDAO;
    I have gone through the reference document, but it has not been explained clearly. Can you please guide me on this.

    Thanks a lot.

  • #2
    You don't need to define any beans on your xml and all it need is component scanning(with spring 3.1. you don't need xml at all!!!).

    You need to annotate your class with one of the stereotype annotations such as @component.
    More info here:

    You can further narrow it down using @Qualifier annotation if you have 2 beans of same type.

    Note: I would use @repository since 'XYZDAO' is a dao class and @repository provides exception translation by default.

    Hope this helps