Announcement Announcement Module
No announcement yet.
Where to define Application context file Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Where to define Application context file


    I am working on the Enterprise java project which includes Jsf (in the front end i.e web layer), EJB on the back end. The architecture will roughly go like this

    jspx->Jsf action classes->EJB service beans->helper classes to process business logic --> DAO layer.

    Now I want to implement Spring IOC between EJB and Dao layer. I have written a application context file with all required beans and injections. But my question is that where to define this application context file?

    I know that it should be defined in web.xml under
    if it is the web project but I am implementing this on enterprise layer rather than web layer could any can help me out on this please

    Last edited by shiva_m; Aug 13th, 2010, 05:25 AM. Reason: typo corrections

  • #2
    We have done several projects like this. We had web project, web services, EJB , hibernate all in one J2EE project with use of spring.

    Read spring reference about loading single context in J2EE application also
    follow link

    You need to define single application context in beanRefContext.xml
    in that file you define your application context
    <bean id="applicationContext" class=" thXmlApplicationContext">


    read this

    While using Spring in EJB follow this link.

    Use Spring's for Session and Message-Driven Enterprise JavaBeans. Spring's provides abstract classes that Enterprise JavaBeans (EJB) may extend. These abstract EJB classes assist development by including standard implementations for EJB lifecycle methods. More importantly, these classes provide mechanisms for loading Spring's application context, including sharing the context across multiple EJBs and clients and therefore reducing duplication and overhead during EJB initialization.


    • #3
      Dear Rajesh,

      Thanks for the reply. Can you please tell me where to define the beanRefContext.xml file in the EJB layer.



      • #4
        You can create seperate jar project and define beanRefContext.xml
        Since this file is shareable between war and ejb modules.

        In our case we have created maven and in eclipse many sub projects like this.

        one ear project ( enterprise application project in ecllipse)
        2 ejb projects ( ejb project in eclpse )
        2 jar projects ( simple java project in eclipse )
        2 web project ( dynamica projects in eclpse 1 was web and 1 was web service )

        we kept benRefContext in common jar project which was simple java project in eclipse. you have to add dependency of this project to all projects.

        in ejb you have to extend Spring Abstract ejb classes as per link i have mentioned. for example for MDB AbstractJmsMessageDrivenBean for statless session bean spring gave you AbstractStatelessSessionBean
        you mest extend respective ejb classes.

        in ejbs setContext method

        1) super.setSessionContext(context);
        2) setBeanFactoryLocator("beanRefContext.xml"); // If you have stored in other than root then com/mycontext/beeanRefContext.xml
        3)setBeanFactoryLocatorKey("applicationContext"); // this is you bean id.

        your benRefContext.xml will look like this.

        <bean id="applicationContext" class=" thXmlApplicationContext">
        <value>my-dao.xml</value> <-- define your dao beans -->

        In your ejb you need to access spring beans like this.

        //getBeanFactory is super class method of springs abstract clas


        • #5
          Hello.. i am also new here. i am hussey from usa. i want to join this forum. because i have listened to my friends about this forum. so i have decided to become a member of this forum. and i also need some help and guidance from the peoples. i am sure peoples will help me when i need their help..

          Term Papers


          • #6
            Hi you do not have to reply this thread.
            you just register with spring source and you can click Forum link under forum
            you can choose topic you want to participate in.

            Either you can reply to problem posted by someone.
            or you post your problem so anyone can reply or give a sollution to you.


            • #7
              There are prayers to:

              Application pages



              Component factories

              Exception Handling