我不能从另一个ejb模块注入远程ejb。我把应用程序分成一个库和两个ejb模块。我尝试通过远程接口从一个ejb模块访问另一个模块,并获得javax.naming.NameNotFoundExc0019。我尝试从NewBean"@EJB私有CountryFacadeRemote"访问。我用了玻璃鱼。
我必须配置一些东西?谢谢。
下载源代码
MyAppTestEJB域名库:
*国家:
public class Country implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@Column(name = "id")
private Long id;
@Basic(optional = false)
@Column(name = "name")
private String name;
...
}
*CountryFacadeRemote:
@Remote
public interface CountryFacadeRemote {
void create(Country country);
void edit(Country country);
void remove(Country country);
Country find(Object id);
List<Country> findAll();
List<Country> findRange(int[] range);
int count();
}
MyAppTestEJB:(ejb模块)
*抽象立面:
public abstract class AbstractFacade<T> {
private Class<T> entityClass;
public AbstractFacade(Class<T> entityClass) {
this.entityClass = entityClass;
}
protected abstract EntityManager getEntityManager();
...
public int count() {
javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
javax.persistence.criteria.Root<T> rt = cq.from(entityClass);
cq.select(getEntityManager().getCriteriaBuilder().count(rt));
javax.persistence.Query q = getEntityManager().createQuery(cq);
return ((Long) q.getSingleResult()).intValue();
}
}
*CountryFacade:
@Stateless
public class CountryFacade extends AbstractFacade<Country> implements CountryFacadeLocal, CountryFacadeRemote {
@PersistenceContext(unitName = "pu")
private EntityManager em;
@Override
protected EntityManager getEntityManager() {
return em;
}
public CountryFacade() {
super(Country.class);
}
}
MyAppTestEJB其他:(ejb模块)
*纽比恩:
@Singleton
public class NewBean {
@EJB
private CountryFacadeRemote countryFacade;
@Schedule(hour = "*", minute = "*")
public void businessMethod() {
System.out.println("NumCountries:" + countryFacade.count());
}
}
错误输出:
WARNING: EJB5184:A system exception occurred during an invocation on EJB NewBean, method: public void net.myapp.myapptestejbother.NewBean.businessMethod()
WARNING: javax.ejb.EJBException: javax.ejb.CreateException: Initialization failed for Singleton NewBean
at com.sun.ejb.containers.AbstractSingletonContainer$SingletonContextFactory.create(AbstractSingletonContainer.java:656)
at com.sun.ejb.containers.AbstractSingletonContainer.instantiateSingletonInstance(AbstractSingletonContainer.java:396)
at org.glassfish.ejb.startup.SingletonLifeCycleManager.initializeSingleton(SingletonLifeCycleManager.java:219)
at org.glassfish.ejb.startup.SingletonLifeCycleManager.initializeSingleton(SingletonLifeCycleManager.java:180)
at com.sun.ejb.containers.AbstractSingletonContainer.checkInit(AbstractSingletonContainer.java:368)
at com.sun.ejb.containers.CMCSingletonContainer._getContext(CMCSingletonContainer.java:116)
at com.sun.ejb.containers.BaseContainer.getContext(BaseContainer.java:2516)
at com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:1906)
at com.sun.ejb.containers.BaseContainer.callEJBTimeout(BaseContainer.java:3990)
at com.sun.ejb.containers.EJBTimerService.deliverTimeout(EJBTimerService.java:1199)
at com.sun.ejb.containers.EJBTimerService.access$000(EJBTimerService.java:89)
at com.sun.ejb.containers.EJBTimerService$TaskExpiredWork.run(EJBTimerService.java:1919)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Caused by: javax.ejb.CreateException: Initialization failed for Singleton NewBean
at com.sun.ejb.containers.AbstractSingletonContainer.createSingletonEJB(AbstractSingletonContainer.java:483)
at com.sun.ejb.containers.AbstractSingletonContainer.access$000(AbstractSingletonContainer.java:81)
at com.sun.ejb.containers.AbstractSingletonContainer$SingletonContextFactory.create(AbstractSingletonContainer.java:654)
... 17 more
Caused by: java.lang.IllegalStateException: Exception attempting to inject Remote ejb-ref name=net.myapp.myapptestejbother.NewBean/countryFacade,Remote 3.x interface =net.myapp.ejb.CountryFacadeRemote,ejb-link=null,lookup=,mappedName=,jndi-name=net.myapp.ejb.CountryFacadeRemote,refType=Session into class net.myapp.myapptestejbother.NewBean: Lookup failed for 'java:comp/env/net.myapp.myapptestejbother.NewBean/countryFacade' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}
at org.glassfish.weld.services.InjectionServicesImpl.aroundInject(InjectionServicesImpl.java:145)
at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:46)
at org.jboss.weld.injection.producer.DefaultInjector.inject(DefaultInjector.java:64)
at org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:91)
at org.glassfish.weld.services.JCDIServiceImpl.injectEJBInstance(JCDIServiceImpl.java:257)
at com.sun.ejb.containers.BaseContainer.injectEjbInstance(BaseContainer.java:1683)
at com.sun.ejb.containers.AbstractSingletonContainer.createSingletonEJB(AbstractSingletonContainer.java:443)
... 19 more
Caused by: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Remote ejb-ref name=net.myapp.myapptestejbother.NewBean/countryFacade,Remote 3.x interface =net.myapp.ejb.CountryFacadeRemote,ejb-link=null,lookup=,mappedName=,jndi-name=net.myapp.ejb.CountryFacadeRemote,refType=Session into class net.myapp.myapptestejbother.NewBean: Lookup failed for 'java:comp/env/net.myapp.myapptestejbother.NewBean/countryFacade' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:717)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:484)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:170)
at org.glassfish.weld.services.InjectionServicesImpl.aroundInject(InjectionServicesImpl.java:138)
... 25 more
Caused by: javax.naming.NamingException: Lookup failed for 'java:comp/env/net.myapp.myapptestejbother.NewBean/countryFacade' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=net.myapp.myapptestejbother.NewBean/countryFacade,Remote 3.x interface =net.myapp.ejb.CountryFacadeRemote,ejb-link=null,lookup=,mappedName=,jndi-name=net.myapp.ejb.CountryFacadeRemote,refType=Session' . Actual (possibly internal) Remote JNDI name used for lookup is 'net.myapp.ejb.CountryFacadeRemote#net.myapp.ejb.CountryFacadeRemote' [Root exception is javax.naming.NamingException: Lookup failed for 'net.myapp.ejb.CountryFacadeRemote#net.myapp.ejb.CountryFacadeRemote' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: net.myapp.ejb.CountryFacadeRemote#net.myapp.ejb.CountryFacadeRemote not found]]]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:491)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:613)
... 28 more
Caused by: javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=net.myapp.myapptestejbother.NewBean/countryFacade,Remote 3.x interface =net.myapp.ejb.CountryFacadeRemote,ejb-link=null,lookup=,mappedName=,jndi-name=net.myapp.ejb.CountryFacadeRemote,refType=Session' . Actual (possibly internal) Remote JNDI name used for lookup is 'net.myapp.ejb.CountryFacadeRemote#net.myapp.ejb.CountryFacadeRemote' [Root exception is javax.naming.NamingException: Lookup failed for 'net.myapp.ejb.CountryFacadeRemote#net.myapp.ejb.CountryFacadeRemote' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: net.myapp.ejb.CountryFacadeRemote#net.myapp.ejb.CountryFacadeRemote not found]]
at com.sun.ejb.EjbNamingReferenceManagerImpl.resolveEjbReference(EjbNamingReferenceManagerImpl.java:188)
at com.sun.enterprise.container.common.impl.ComponentEnvManagerImpl$EjbReferenceProxy.create(ComponentEnvManagerImpl.java:1143)
at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:745)
at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:715)
at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:159)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:471)
... 32 more
Caused by: javax.naming.NamingException: Lookup failed for 'net.myapp.ejb.CountryFacadeRemote#net.myapp.ejb.CountryFacadeRemote' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: net.myapp.ejb.CountryFacadeRemote#net.myapp.ejb.CountryFacadeRemote not found]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:491)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at com.sun.ejb.EjbNamingReferenceManagerImpl.resolveEjbReference(EjbNamingReferenceManagerImpl.java:183)
... 37 more
Caused by: javax.naming.NameNotFoundException: net.myapp.ejb.CountryFacadeRemote#net.myapp.ejb.CountryFacadeRemote not found
at com.sun.enterprise.naming.impl.TransientContext.doLookup(TransientContext.java:237)
at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:204)
at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:66)
at com.sun.enterprise.naming.impl.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:114)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:478)
... 41 more
WARNING: EJB5184:A system exception occurred during an invocation on EJB NewBean, method: public void net.myapp.myapptestejbother.NewBean.businessMethod()
WARNING: javax.ejb.NoSuchEJBException: Singleton NewBean is unavailable because its original initialization failed.
at com.sun.ejb.containers.AbstractSingletonContainer.checkInit(AbstractSingletonContainer.java:359)
at com.sun.ejb.containers.CMCSingletonContainer._getContext(CMCSingletonContainer.java:116)
at com.sun.ejb.containers.BaseContainer.getContext(BaseContainer.java:2516)
at com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:1906)
at com.sun.ejb.containers.BaseContainer.callEJBTimeout(BaseContainer.java:3990)
at com.sun.ejb.containers.EJBTimerService.deliverTimeout(EJBTimerService.java:1199)
at com.sun.ejb.containers.EJBTimerService.access$000(EJBTimerService.java:89)
at com.sun.ejb.containers.EJBTimerService$TaskExpiredWork.run(EJBTimerService.java:1919)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
解决了在EJB注释中添加lookup
的问题:
@EJB(lookup=“java:global/MyAppTestEJB/CountryFacade!net.myapp.EJB.CountryFacadeRemote”)
@Singleton
public class NewBean {
@EJB(lookup = "java:global/MyAppTestEJB/CountryFacade!net.myapp.ejb.CountryFacadeRemote")
private CountryFacadeRemote countryFacade;
@Schedule(hour = "*", minute = "*")
public void businessMethod() {
System.out.println("NumCountries:" + countryFacade.count());
}
}
有没有更优雅的方法来做到这一点?
我目前的问题是,我的机器上运行了两个Wildfly 8.2.0最终实例。我知道,有类似的问题,但没有一个真正有助于我的问题。其中一个拥有一个宁静的应用程序,当它收到GET时,它会触发无状态会话Bean。之后,此无状态会话 Bean 应从远程无状态会话 Bean 调用方法该方法位于另一个 wildfly 实例上。 我将从解释我到目前为止所做的事情开始(也许我错过了一些东西,我对Java EE和Wil
我需要帮助从Spring调用EJB远程接口。 web应用程序部署在同一个JBoss服务器中。但是当我尝试部署时,我得到一个命名异常'ServiceBean'未绑定。我必须在web.xml中添加环境条目才能访问EJB吗(即使EJB和web应用程序都部署在同一个JBoss中)?
问题内容: 我在远程Glassfish服务器和计算机上的应用程序客户端中都有一个EJB模块。我想从应用程序客户端连接到远程EJB。 这是我的EJB接口: 这是我的ejb: 我有几个问题: 我可以在远程应用程序客户端中使用依赖注入来连接到ejb吗?如果是这样,我该怎么做才能做到这一点。我是否需要在sun-ejb-jar.xml和sun-application-client.xml中进行配置?换句话说
我有一个EAR应用程序,有三个模块: null 这是工作良好的,但现在我必须使用相同的豆子外耳应用程序,注射是不工作的。 我在app-ejb中有: 以及他在app-remote中的远程界面: 这是意料之中的吗?如何才能正确地注入远程bean?
我需要能够从这个简单的摇摆java应用程序调用保存()方法到我的Web应用程序,该应用程序在服务器上发布,其中包含我用来保存新实体类型类角色的bean,该类具有名称、地址、电子邮件。 我在使用wildfly 8。x代表我的服务器,并按以下方式发布我的web应用: 这是我的ContactoDAO Bean: 在我的简单客户端swing应用程序上,我的设置如下: 您可以在上面的代码中看到我使用它来调用
我在NetBeans中创建了一个带有EJB模块和web模块的Java EE应用程序。业务逻辑驻留在EJB模块内部的EJB中。web模块的托管bean是否可以访问EJB模块内部的EJB?怎么做? (JDK 1.7、Java EE 6、Glassfish 3.1.2.2、NetBeans IDE 7.2)