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 {}
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.