Results 1 to 4 of 4

Thread: Weblogic 10.3 @EJB SpringBeanAutowiringInterceptor

  1. #1

    Default Weblogic 10.3 @EJB SpringBeanAutowiringInterceptor

    Hi

    Spring 2.5.6.

    I am having a problem with an EJB 3.0 running inside WLS 10.3.1.

    Note, the EJB is using:

    @Stateless
    @Interceptors(SpringBeanAutowiringInterceptor.clas s)
    public class MyEjb {

    @EJB
    AnotherEJB anotherEjb; // EJB

    @Autowired
    @Qualifier("aBean")
    MyInterface myInterface; // Spring bean
    }

    @EJB annotation does not resolve the EJB correctly, bea internal classes try to resolve the EJB through Spring (but does not get into Spring classes).

    If I move the @EJB annotation out into a static factory class (ie. one that does not have @Interceptors(SpringBeanAutowiringInterceptor.clas s) at the top of the class, then it works fine.

    Any ideas?

  2. #2

    Default

    @bendg25,

    I've been trying to locate/create an example of what you said works for you. Is there anyway I could get a copy of the project files that work?

    I'm trying to get an example of an EJB3 stateless session bean to delegate a method call to a Spring 3.0 managed bean running in an EJB container on a Oracle/Weblogic 10.3 instance. I haven't had much luck yet trying to piece together all the tidbits of information spread around the webverse.

    If you can't supply the project files, any hints as to where you found the information on how to put together all the files would be very helpful and appreciated.

    Thanks!

  3. #3
    Join Date
    Nov 2008
    Posts
    8

    Default

    @sherpa,

    Did you ever figure this out. I am running into the same issue.

  4. #4

    Default EJB 3 / Spring 3 Example

    Yes I have...here is my example...

    Business Interface - Utility.java
    Code:
    package com.intsrv.srv.client;
    public interface Utility {
    	public String echoService(String echoString);
    }
    EJB Local Interface - UtilityEJBLocal.java
    Code:
    package com.intsrv.srv.client;
    import javax.ejb.Local;
    @Local
    public interface UtilityEJBLocal extends Utility {}
    EJB Remote Interface - UtilityEJBRemote.java
    Code:
    package com.intsrv.srv.client;
    import javax.ejb.Remote;
    @Remote
    public interface UtilityEJBRemote extends Utility {}
    EJB - UtilityEJB.java
    Code:
    package com.intsrv.srv.ejb;
    import java.io.Serializable;
    import javax.ejb.Stateless;
    import javax.interceptor.Interceptors;
    import org.apache.log4j.Logger;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor;
    import com.intsrv.srv.EJBSpringGateway;
    import com.intsrv.srv.client.UtilityEJBLocal;
    import com.intsrv.srv.client.UtilityEJBRemote;
    
    @Stateless(mappedName="ejb/UtilityEJB")
    @Interceptors(SpringBeanAutowiringInterceptor.class)
    public class UtilityEJB implements UtilityEJBLocal, UtilityEJBRemote, Serializable {
    	private static final long serialVersionUID = 1L;
    	private static final Logger log = Logger.getLogger(UtilityEJB.class);
    
    	@Autowired
    	private EJBSpringGateway eJBSpringGateway;
    
    	public UtilityEJB (){
    		log.info("Creating DEFAULT UtilityEJB instance.");
    	}
    
    	@Override
    	public String echoService(String echoString) {
    		log.info("echoService()");
    		return eJBSpringGateway.echoService(echoString);
    	}
    }
    Gateway Interface - EJBSpringGateway.java
    Code:
    package com.intsrv.srv;
    import com.intsrv.srv.client.Utility;
    public interface EJBSpringGateway extends Utility {}
    Gateway Implementation - EJBSpringGatewayImpl.java
    Code:
    package com.intsrv.srv;
    import org.apache.log4j.Logger;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.annotation.Scope;
    import org.springframework.stereotype.Service;
    import com.intsrv.srv.client.Utility;
    
    @Service("eJBSpringGateway")
    @Scope("prototype")
    public class EJBSpringGatewayImpl implements EJBSpringGateway {
    	private static final Logger log = Logger.getLogger(EJBSpringGatewayImpl.class);
    	private int instanceCheck = 1;
    
    	@Autowired
    	private ApplicationContext context;
    
    	// Default Constructor
    	public EJBSpringGatewayImpl(){
    		log.info("Creating DEFAULT EJBSpringGatewayImpl instance.");
    	}
    	
    	public String echoService(String echoString) {
    		log.info("echoService()");
    		Utility utility = (Utility)context.getBean("utility");
    		return "esg{"+(instanceCheck++)+"}"+utility.echoService(echoString);
    	}
    }
    Business Implementation - UtilityImpl.java
    Code:
    package com.intsrv.srv.utility;
    import org.apache.log4j.Logger;
    import org.springframework.context.annotation.Scope;
    import org.springframework.stereotype.Service;
    import com.intsrv.srv.client.Utility;
    
    @Service("utility")
    @Scope("prototype")
    public class UtilityImpl implements Utility {
    	private static final Logger log = Logger.getLogger(UtilityImpl.class);
    
    	public UtilityImpl(){
    		log.info("Creating DEFAULT UtilityImpl instance.");
    	}
    
    	public String echoService(String echoString) {
    		log.info("echoService()");
    		return (echoString);
    	}
    }
    Spring Application Configuration - applicationContext.xml
    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:aop="http://www.springframework.org/schema/aop"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    	xmlns:jee="http://www.springframework.org/schema/jee"
    	xmlns:jms="http://www.springframework.org/schema/jms"
    	xmlns:lang="http://www.springframework.org/schema/lang"
    	xmlns:p="http://www.springframework.org/schema/p"
    	xmlns:task="http://www.springframework.org/schema/task"
    	xmlns:tx="http://www.springframework.org/schema/tx"
    	xmlns:util="http://www.springframework.org/schema/util"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    		http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
    		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
    		http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd
    		http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd
    		http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
    		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
    
           <context:component-scan base-package="com.intsrv"/>
           <context:annotation-config/>
    
    </beans>
    Spring Configuration - Bean Reference Configuration - beanRefContext.xml
    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:aop="http://www.springframework.org/schema/aop"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    	xmlns:jee="http://www.springframework.org/schema/jee"
    	xmlns:jms="http://www.springframework.org/schema/jms"
    	xmlns:lang="http://www.springframework.org/schema/lang"
    	xmlns:oxm="http://www.springframework.org/schema/oxm"
    	xmlns:p="http://www.springframework.org/schema/p"
    	xmlns:task="http://www.springframework.org/schema/task"
    	xmlns:tx="http://www.springframework.org/schema/tx"
    	xmlns:util="http://www.springframework.org/schema/util"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    		http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
    		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
    		http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd
    		http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd
    		http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd
    		http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
    		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
    
    	<bean class="org.springframework.context.support.ClassPathXmlApplicationContext">
    	    <constructor-arg type="java.lang.String" value="applicationContext.xml" />
    	</bean>
    
    </beans>
    Spring Configuration - EJBApplicationConfig.java
    Code:
    package com.intsrv.srv;
    import org.apache.log4j.Logger;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.context.annotation.Scope;
    import com.intsrv.srv.client.Utility;
    import com.intsrv.srv.utility.UtilityImpl;
    
    @Configuration()
    public class EJBApplicationConfig {
    	private static final Logger log = Logger.getLogger(EJBApplicationConfig.class);
    
    	public EJBApplicationConfig(){
    		log.info("Creating DEFAULT EJBApplicationConfig instance.");
    	}
    
    	@Bean
    	@Scope("prototype")
    	public EJBSpringGateway eJBSpringGateway() {
    		log.info("eJBSpringGateway()");
    		return new EJBSpringGatewayImpl();
    	}
    	
    	@Bean
    	@Scope("prototype")
    	public Utility utility() {
    		log.info("utility()");
    		return new UtilityImpl();
    	}
    }
    Notes:
    1) applicationContext.xml and beanRefContext.xml files are located in the root src folder.
    2) I fully admit that the "Gateway" object is an intermediary that is not neccessary to have an EJB communicate to a Spring bean. I have it in there to provide for the opportunity to get a new Spring bean for each new EJB call. Otherwise, each EJB, which only gets instantiated once (even though its stateless), will get one instance of the Spring bean. That may or may not be OK, but it wasn't what I needed. I needed a new Spring bean instance each time I had a SLSB called. Please let me know if you have any questions. Thanks.
    Last edited by sherpa; Feb 28th, 2011 at 11:45 AM.

Posting Permissions

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