请问下有Ejb3+Spring3+SpringMVC的例子嘛,或者讲讲他们之间怎么调用?
我们的项目情况如下:
Spring3是一个工程
ejb3又是一个工程
用的jboss5发布的
听说是Spring里面的Service调用EJB里面的service
我搞不懂这之间的关系,
求大神给个源码,或者文档啥的,学习下,谢谢了。
------解决方案--------------------
srping调用ejb,
很简单的
定义一个ejb 远程接口
@Remote
public interface PCBService{}
@Stateless(mappedName = "service.xxService")
@LocalBean
public class xxBean implements xxService{}
在spring的service里
用
@Resource(mappedName = "service.xxService")注入就好了。
也可以用jndi,
spring配置文件。
但是ejb要是远程接口哦,即使是同一个jvm,
------解决方案--------------------
EjbTools, 初始化JNDI, 根据EJB的JNDI名称获取EJB
package com.wanghy.j2ee;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;
import javax.ejb.EJBObject;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
public class EjbTools {
private static final String PROPERTY_FILE_NAME = "EjbTools.properties";
private static Properties props;
private synchronized void loadProperties() throws IOException {
if(props == null){
java.io.InputStream inputstream = ClassLoader.getSystemClassLoader().getResourceAsStream(PROPERTY_FILE_NAME);
if (inputstream == null){
inputstream = this.getClass().getClassLoader().getResourceAsStream(PROPERTY_FILE_NAME);
if (inputstream == null){
throw new IOException("Read properties file error:" + PROPERTY_FILE_NAME);
}
}
props = new Properties();
props.load(inputstream);
}
}
public InitialContext getInitialContext() throws NamingException, IOException {
loadProperties();
Properties properties = new Properties();
properties.put("java.naming.factory.initial", props.getProperty("jndi.initialContextFactory"));
properties.put("java.naming.provider.url", props.getProperty("jndi.providerUrl"));
properties.put("java.naming.security.principal", props.getProperty("jndi.securityPrincipal"));
properties.put("java.naming.security.credentials", props.getProperty("jndi.securityCredentials"));
InitialContext initialcontext = new InitialContext(properties);
return initialcontext;
}
public static EJBObject getEJBObject(String s) throws NamingException, IOException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException{
EjbTools tool = new EjbTools();
InitialContext initialcontext = tool.getInitialContext();
Object home = initialcontext.lookup(s);
Class homeClass = home.getClass();