Announcement Announcement Module
Collapse
No announcement yet.
weblogic 8.1 injected EJB into Spring MVC Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • weblogic 8.1 injected EJB into Spring MVC

    sup !

    i'm running weblogic 8.1 (no kiddin). I have this simple spring application i wrote using spring mvc. Basically i used the SimpleRemoteStatelessSessionProxyFactoryBean to call my EJB using the following in my spring-app.xml file:

    Code:
    <bean id="testEJB" class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean">
    <property name="jndiName" value="testJNDI" />
    <property name="businessInterface" value="my.test.ejb.simpleRemote" />
    </bean>
    After injecting this into a bean that I want to use it from, when I call the remote interface method using the injected bean name: testEJB.hello(); my code is fails to compile.
    It says: cannot resolve symbol hello(); its not compiling. BUt If i remove the .hello() and compile the code it compiles fine. But if I try to call a business method defined in the remote it is not compiling.

  • #2
    Post your controller. My guess you aren't injecting the actuall bean or it is of the wrong type (not simpleRemote or your simpleRemote interface doesn't have the method defined).

    Comment


    • #3
      Marten thnx for you're response.
      The application I am using is a very light implmentation of Spring 2.5 utilizing only the MVC package. I am not using any controller at all. The request is being sent by an AJAX method directly to the service class. The service class has a one method in which I am calling simple stateless session bean having a hello world method. My purpose is grasp how to call an EJB. With the above code I posted, Spring does give me clusterableRemoteObject to the remote interface of the session bean. I just cant call any of the methods in the remote interface because code is not compiling. Maven complains that it cannot find hello() method, and compilation fails. I have included the EJBTestClient.jar in my classpath as well. I even created a local interface within my code to mimic the business methods in the remote but remove RemoteException. The code compiled but it deploy exception is:
      Initialization of bean failed; nested exception is
      Code:
      org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy18] to required type

      Comment


      • #4
        As I stated post the code, you are using the wrong type.

        Comment


        • #5
          Marten here is my code:

          I would greatly appreciate it if you can guide me where I am using the wrong type and how to rectify it.
          Kindly give details please.


          This is the class deployed as a web application that is calling an EJB. Both are running on Weblogic 8.1.
          Code:
          package com.billy.service;
          
          import net.billy.ejbs.HelloEJB;
          	
          public class helloServiceImpl implements Service
          {
          
                //remote ejb interface
                private HelloEJB helloEJBRemote;
          	
                //this is where the code is failing to compile at the line where i am callling
                //the hello business method.
                 public String callHelloBean() 
                   {
          		//this is where i am calling the hello method in my remote  
                          //interface i.e helloEJBRemote.hello()
                          String temp =  helloEJBRemote.hello();
                          System.out.println("EJB CALLING:  " +  temp); 
          		return temp;
          	}
          	
          	
          	//Spring DI for injecting the EJB remote interface into this class
          	public void sethelloEJBRemote(HelloEJB helloEJBRemote) {
          		this.helloEJBRemote=helloEJBRemote;
          	}
          Here is the Remote:

          Code:
          package net.billy.ejbs.HelloEJB;
          
          import java.rmi.RemoteException;
          import java.util.ArrayList;
          import java.util.Map;
          
          
          
          public interface HelloEJB extends javax.ejb.EJBObject 
          	{
          		public String hello() throws RemoteException;
          	}

          Here is the Home Interface
          Code:
          package net.billy.ejbs;
          
          import javax.ejb.*;
          import java.util.*;
          import java.rmi.*;
          
          public interface HelloEJBHome extends javax.ejb.EJBHome {
            public HelloEJB create() throws CreateException, RemoteException;
          }
          Here is the Session Bean:

          Code:
          package net.billy.ejbs;
          
          import java.io.FileInputStream;
          import java.io.IOException;
          import java.rmi.RemoteException;
          import java.util.ArrayList;
          import java.util.Map;
          import java.util.Properties;
          
          import javax.ejb.CreateException;
          import javax.ejb.EJBException;
          import javax.ejb.SessionBean;
          import javax.ejb.SessionContext;
          
          
          public class HelloEJBBean implements SessionBean {
            SessionContext sessionContext;
            
            public void ejbCreate() throws CreateException {
              System.out.println("ejbCreate called...");
            }
          
            public void ejbRemove() {
              System.out.println("ejbRemove called...");
            }
            
            public void ejbActivate() {
              System.out.println("ejbActivate called...");
            }
            
            public void ejbPassivate() {
              System.out.println("ejbPassivate called...");
            }
            
            public void setSessionContext(SessionContext sessionContext) {
              this.sessionContext = sessionContext;
            }
          
          //business methods 
              public String hello() {
          		return "hello():  Hello, World From Session Bean";
            }
          }
          Here is the spring context file injecting the EJB into the service class at the top:
          Code:
          <?xml version="1.0" encoding="UTF-8"?>
          <beans
            xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr" xmlns:jee="http://www.springframework.org/schema/jee"
            xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.directwebremoting.org/schema/spring-dwr
              http://www.directwebremoting.org/schema/spring-dwr-2.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd">
          	
          	
          <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                      <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
              	    <property name="prefix" value="/WEB-INF/views/" />
                      <property name="suffix" value=".jsp" />
                  </bean>
          	
          		<bean id="viewPage" class="org.springframework.web.servlet.mvc.UrlFilenameViewController"/>
                  
               
          		<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
          			<property name="mappings">
          				<props>
          					<prop key="/helloworld.htm">viewPage</prop>
          				</props>
          			</property>
          		</bean>
                  
                   <!--  DWR Configuration -->
                   <dwr:configuration>
          			<dwr:convert class="com.billy.beans.HelloBean" type="bean" />
                   </dwr:configuration>
          				            
              			  <bean id="helloServiceImpl" class="mil.army.cpol.cisd.hdadmin.service.MaintainMasterListServiceImpl">
          						<property name="helloEJBRemote"><ref bean="HelloEJB " /></property>
          						<!-- for dwr only -->
          						<dwr:remote javascript="helloServiceImpl">
          							<dwr:include method="callHelloBean" />   
          						</dwr:remote>
                            </bean> 
          				                				
          				<!-- ejb stateless remote test -->
          				<bean id="HelloEJB" class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean">
          						<property name="jndiName" value="BillyDataSource" />
          						<property name="businessInterface" value="net.billy.ejbs.HelloEJB" />
          				</bean>
          				<!-- end ejb test -->
          				
             </beans>
          Last edited by billy_cool; Mar 9th, 2010, 11:43 AM.

          Comment


          • #6
            For starters you shouldn't use the remote interface as the business interface, it is better (for decoupling) to create a separate business interface that way you don't hvae to handle remote exceptions. This business interface can be part of your web project.

            Code:
            public interface HelloBusiness  {
            	public String hello();
            }
            Next to that on some servers it might be needed to specify/configure the home interface on the ProxyfactoryBean. Finally you say it isn't compiling have you included the ejb-client jar on the classpath of your web project?

            Comment


            • #7
              How do i do this:
              "it might be needed to specify/configure the home interface on the ProxyfactoryBean"

              Are you sure it need to be done with weblogic. Would you by any chance have a working example of this that I could use to follow along. Thanks.

              Comment


              • #8
                No I'm not sure and it has been about 6 years since I last used EJBs so no sample.

                Comment


                • #9
                  i m sending source code some error are occured

                  <%@ taglib prefix="spring" uri="/spring" %>
                  <html>

                  <head><title>Login please.</title></head>
                  <body>
                  <form method="post">
                  <table>
                  <tr><td>Enter your first number</td>
                  <spring:bind path="credentials.num1">
                  <td><input type="text" name="num1" /></td>
                  </spring:bind>
                  </tr>
                  <tr><td>Enter your second number</td>
                  <spring:bind path="credentials.num2">
                  <td><input type="text" name="num2" /></td>
                  </spring:bind>
                  </tr>

                  <tr><td>Enter your operation</td>
                  <spring:bind path="credentials.operation">
                  <td><select name="operation">
                  <option>---</option>
                  <option>Add</option>
                  <option>Sub</option>
                  <option>Mul</option>
                  <option>Div</option>
                  </select>
                  </td>
                  </spring:bind>
                  </tr>

                  <tr><td colspan=2><input type="submit" /></td></tr>
                  </table>
                  </form>
                  </body>
                  </html>


                  --------------------------------------------------------------------------

                  <?xml version="1.0" encoding="UTF-8"?>
                  <!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN'
                  'http://java.sun.com/dtd/web-app_2_3.dtd'>

                  <web-app>

                  <servlet>
                  <servlet-name>dispatcher</servlet-name>
                  <servlet-class>
                  org.springframework.web.servlet.DispatcherServlet
                  </servlet-class>
                  <load-on-startup>1</load-on-startup>
                  </servlet>

                  <servlet-mapping>
                  <servlet-name>dispatcher</servlet-name>
                  <url-pattern>*.do</url-pattern>
                  </servlet-mapping>

                  <taglib>
                  <taglib-uri>/spring</taglib-uri>
                  <taglib-location>/WEB-INF/spring.tld</taglib-location>
                  </taglib>

                  </web-app>
                  ---------------------------------------------------------------------------package com.check.spring.mvc.login;

                  public class LoginCredentials
                  {
                  private String num1;
                  private String num2;
                  private String operation;
                  public LoginCredentials()
                  {

                  }
                  public void setNum1(String num1)
                  {
                  this.num1=num1;
                  }
                  public String getNum1()
                  {
                  return num1;
                  }
                  public void setNum2(String num2)
                  {
                  this.num2=num2;
                  }
                  public String getNum2()
                  {
                  return num2;
                  }
                  public void setOperation(String operation)
                  {
                  this.operation=operation;
                  }

                  public String getOperation()
                  {
                  return operation;
                  }


                  }
                  --------------------------------------------------------------------------

                  package com.check.spring.mvc.login;

                  import org.springframework.web.servlet.ModelAndView;
                  import org.springframework.web.servlet.mvc.SimpleFormCont roller;

                  public class LoginFormController extends SimpleFormController
                  {


                  protected ModelAndView onSubmit(Object command) throws Exception {
                  LoginCredentials credentials = (LoginCredentials) command;
                  System.out.println("Number1: " + credentials.getNum1());
                  System.out.println("Number2: " + credentials.getNum2());
                  return super.onSubmit(command);
                  }
                  }
                  --------------------------------------------------------------------------

                  <?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="Login"
                  class="com.check.spring.mvc.login.LoginFormControl ler">
                  <property name="sessionForm">
                  <value>true</value>
                  </property>
                  <property name="commandName">
                  <value>credentials</value>
                  </property>
                  <property name="commandClass">
                  <value>com.check.spring.mvc.login.LoginCredentials </value>
                  </property>
                  <property name="formView">
                  <value>/WEB-INF/jsp/loginform.jsp</value>
                  </property>
                  </bean>

                  <bean id="urlMapping"
                  class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
                  <property name="urlMap">
                  <map>
                  <entry key="/login.do">
                  <ref bean="Login" />
                  </entry>
                  </map>
                  </property>
                  </bean>

                  </beans>

                  Comment

                  Working...
                  X