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

  • Where to define Application context file

    Hi,

    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
    Code:
    <context-param>ContextConfigLocation</context-param>
    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

    Regards,
    Shiva
    Last edited by shiva_m; Aug 13th, 2010, 06: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="org.springframework.context.support.ClassPa thXmlApplicationContext">
    <constructor-arg>
    <list>
    <value>dao-context.xml</value>
    <value>service-context.xml</value>

    </list>
    </constructor-arg>
    </bean>

    etc.
    read this

    http://blog.springsource.com/2007/06...g-application/



    While using Spring in EJB follow this link.

    http://www.oracle.com/technetwork/ar...ng-096279.html


    Use Spring's org.springframework.ejb.support for Session and Message-Driven Enterprise JavaBeans. Spring's org.springframework.ejb.support 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.

    Comment


    • #3
      Dear Rajesh,

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

      Thanks,
      Shiva

      Comment


      • #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
        call

        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="org.springframework.context.support.ClassPa thXmlApplicationContext">
        <constructor-arg>
        <list>
        <value>my-dao.xml</value> <-- define your dao beans -->
        <value>my-servic.xml</value>
        </list>
        </constructor-arg>
        </bean>

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

        getBeanFactory().getBean("myDao");
        //getBeanFactory is super class method of springs abstract clas

        Comment


        • #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

          Comment


          • #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.

            Comment


            • #7
              There are prayers to:

              Application pages

              Binding

              Orders

              Component factories

              Exception Handling

              Appearance

              Remoting

              Security

              Views

              Comment

              Working...
              X