Announcement Announcement Module
No announcement yet.
weblogic 8.1 injected EJB into Spring MVC Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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:

    <bean id="testEJB" class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean">
    <property name="jndiName" value="testJNDI" />
    <property name="businessInterface" value="my.test.ejb.simpleRemote" />
    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).


    • #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
      org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy18] to required type


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


        • #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.
          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) {
          Here is the Remote:

          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
          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:

          package net.billy.ejbs;
          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:
          <?xml version="1.0" encoding="UTF-8"?>
            xmlns="" xmlns:xsi=""
            xmlns:dwr="" xmlns:jee=""
          <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 id="viewPage" class="org.springframework.web.servlet.mvc.UrlFilenameViewController"/>
          		<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
          			<property name="mappings">
          					<prop key="/helloworld.htm">viewPage</prop>
                   <!--  DWR Configuration -->
          			<dwr:convert class="com.billy.beans.HelloBean" type="bean" />
              			  <bean id="helloServiceImpl" class="">
          						<property name="helloEJBRemote"><ref bean="HelloEJB " /></property>
          						<!-- for dwr only -->
          						<dwr:remote javascript="helloServiceImpl">
          							<dwr:include method="callHelloBean" />   
          				<!-- 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" />
          				<!-- end ejb test -->
          Last edited by billy_cool; Mar 9th, 2010, 12:43 PM.


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

            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?


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


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


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

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

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

                  <tr><td>Enter your operation</td>
                  <spring:bind path="credentials.operation">
                  <td><select name="operation">

                  <tr><td colspan=2><input type="submit" /></td></tr>


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





                  ---------------------------------------------------------------------------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)
                  public String getNum1()
                  return num1;
                  public void setNum2(String num2)
                  public String getNum2()
                  return num2;
                  public void setOperation(String 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"


                  <bean id="Login"
                  class="com.check.spring.mvc.login.LoginFormControl ler">
                  <property name="sessionForm">
                  <property name="commandName">
                  <property name="commandClass">
                  <value>com.check.spring.mvc.login.LoginCredentials </value>
                  <property name="formView">

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