Results 1 to 6 of 6

Thread: Can J2EE/EJB application automatically load applicationContext.xml?

  1. #1

    Default Can J2EE/EJB application automatically load applicationContext.xml?

    I've written a Spring MVC application and it loads my bean .xml file automatically. Is there a way to do this with a J2EE/EJB application for the applicationContext.xml? We're just starting to use Spring in our EJB's and I have it working using:

    ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext .xml");

    I just wonder if there's a better way?

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

    Default

    Loading an ApplicationContext in an EJB (Container) can be bit tricky. The best known and documented approach is using a (Context)SingletonBeanFactoryLocator. You can find more information about Spring and EJB's in the reference guide. Chapter 18.3 gives an explanation about that.

    Your solution will result in multiple ApplicationContexts i.e. one for each EJB instance, not sure if you want that .
    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

  3. #3
    Join Date
    Jan 2006
    Posts
    28

    Default

    For your stateless session beans, you may extends AbstractStatelessSessionBean .

    And define in you ejb-jar.xml the environnment entry: ejb/BeanFactoryPath
    Like this:
    Code:
    <env-entry>
      <env-entry-name>ejb/BeanFactoryPath</env-entry-name>
      <env-entry-type>java.lang.String</env-entry-type>
      <env-entry-value>
        <![CDATA[application-core-dao.xml application-ejb-jndi-datasource.xml 
                 application-business-services.xml 
                 application-business-interfaces.xml
                 application-business-rules-engine.xml ]]>
      </env-entry-value>
    </env-entry>
    In your stateless session bean, you could access the application context's beans with:
    Code:
    getBeanFactory().getBean("myBean")

  4. #4

    Default

    Does someone have any idea why this wouldnt work on weblogic 10?

    I've got stateless session bean (ejb 3.0 spec)
    Code:
    @Stateless(name="echoService")
    public class EchoServiceBean extends AbstractStatelessSessionBean implements EchoService,Serializable {
    .
    @Override
    	protected void onEjbCreate() {
    		 doSomething()
    	}
    }
    And that onEjbCreate() never gets called. I'm clueless

  5. #5
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    The AbstractStatelessSessionBean is to be used for EJB prior to EJB3. It isn't to be used for EJB3.
    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

  6. #6

    Default

    Quote Originally Posted by mdeinum View Post
    The AbstractStatelessSessionBean is to be used for EJB prior to EJB3. It isn't to be used for EJB3.
    Is it really so? I've seen so many examples (for instance "ejb3 in action") where AbstractStatelessSessionBean is used to provide beanfactory.

    Anyway, looks like pitchfork is the way to go in weblogic 10.x.

Posting Permissions

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