Announcement Announcement Module
Collapse
No announcement yet.
Error getting bean in application Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error getting bean in application

    Hi,

    I'm using Spring/Hibernate in a WSAD envirionment and have attempted
    avail the utilities in Spring to do the jndi lookup etc for me given a jindi configuration.

    I'm having difficulty obtaining the refence to a bean held in an xml config file (WASAD classpath) in my application . This xml file is quite comprehensive and it should give Spring the details for an EJB I'm interested in invoking (jndi info etc). NB the application is standalone will run on the same machine but different JVM. Please help! Thanks!

    The xml file is as follows (StockPrice is my EJB remote interface):

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    <bean id="StockPrice" class="org.springframework.ejb.access.SimpleRemote StatelessSessionProxyFactoryBean">
    <property name="jndiName">
    <value>java:comp/env/ejb/StockPrice
    </value>
    </property>
    <property name="businessInterface">
    <value>com.stock.data.services.ejb.StockPrice
    </value>
    </property>
    <property name="environment">
    <props>
    <!-- provide WebSphere AppServer 5.1 environment properties here -->
    <prop key="java.naming.factory.initial">com.ibm.webspher e.naming.WsnInitialContextFactory</prop>
    <prop key="java.naming.provider.url">iiop://localhost:1234/</prop>
    </props>
    </property>
    </bean>
    </beans>


    In my application I have the following code which should return
    the desired bean as an object to the calling program (for casting to the
    EJB StockPrice) :

    NB serviceName = "StockPrice".

    protected Object getService(String serviceName) throws BeansException {

    Object instObject=null;

    try
    {

    instObject = this.getAppCtx().getBeanFactory().getBean(serviceN ame);

    }
    catch (BeansException e)
    {

    } catch (NullPointerException e) {


    } catch (Exception e)
    {

    }
    return instObject;

    }

    However the above code gives me a null pointer exception.

    java.lang.NullPointerException
    at com.stock.data.services.source.getService(Abstract Mace.java:70)

    NB port number for WAS above is noddy.

  • #2
    Hi

    An update on this I now get

    Error creating bean with name 'StockPrice' defined in class path resource [beans-service-test.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'environment' of bean class [org.springframework.ejb.access.SimpleRemoteStatele ssSessionProxyFactoryBean]: Property 'environment' is not writable
    null

    It complains of property environment - I thought this was needed to supply the jndi properties, if this is incorrect what should it be please
    to supply the jndi properties thanks!

    Comment


    • #3
      Aslam,

      The problem here, as far as I can tell, is that either getAppCtx() or getBeanFactory() is returning null. I can't see anything else that could cause a NullPointerException with getService() at the top of the stack. Try splitting the line
      Code:
      instObject = this.getAppCtx&#40;&#41;.getBeanFactory&#40;&#41;.getBean&#40;serviceName&#41;;
      to determine which is returning null. If you have no luck post the code for those methods here as well.

      Rob

      >> ADDED: Looks like we got a cross post there! Just looking at your updated message now.

      Comment


      • #4
        Aslam,

        The property you are looking for is jndiEnvironment not environment.

        Rob

        Comment


        • #5
          Hi Rob,

          Thanks very much indeed for your help. Yes we certainly got cross posts there!

          Just to confirm are you saying that I should replace <property name="environment"> with <property name="jndiEnvironment"> ?

          Would I I be right in saying that Spring will take care of the rest, ie. do the jndi lokup to locate the bean I've defined, given the jndiName and Websphere specific jndi information?

          If I'm not correct please let me know if I've missed any steps! Otherwise
          I will now cast instObject to StockPrice which is my remote interface and then use the handle to access the .create() on the EJB and then invoke the business method.


          Thanks again.

          Regards,

          Aslam.

          Comment


          • #6
            Aslam,

            That is correct - you should replace <property name="environment"> with <property name="jndiEnvironment">.

            With this information Spring will then look up the home interface and create a proxy to the resource. Make sure that you set the businessInterface property to the interface you wish the proxy to implement.

            When obtaining the bean from Spring you simply cast to the appropriate interface type or have Spring inject the bean into another bean. You can simply access the bean as if it were a standard Java class and the Spring proxy will redirect all calls to the remote EJB.

            Rob

            Comment


            • #7
              Thanks for your assistence!

              Regards,

              Aslam.

              Comment

              Working...
              X