Я не могу использовать EJB @Statles remote bean. Он всегда ноль. Весь день я ищу в Интернете учебники, но мой код не работает. У меня есть два проекта: EJB bean in jar package и военный проект. Я хочу ввести бин из банки в войну. Оба развернуты на моем сервере Payara.
Пакет Jar
Реализация:
package eu.pstdio;
import javax.ejb.Stateless;
@Stateless(mappedName="testBean")
public class BeanImpl implements BeanApi {
public String test() {
return "test";
}
}
Интерфейс:
package eu.pstdio;
import javax.ejb.Remote;
@Remote
public interface BeanApi {
String test();
}
И это мой военный код :
Singleton:
package eu.pstdio.restAppKt;
package eu.pstdio.restAppKt;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Singleton;
import javax.ejb.Startup;
@Singleton
@Startup
@LocalBean
public class SimpleRest {
@EJB(mappedName="testBean")
private BeanApi bean;
@PostConstruct
public void test() {
System.out.println(bean.test());
}
}
Реализация компонента:
package eu.pstdio.restAppKt;
public interface BeanApi {
String test();
}
Журнал развертывания веб-приложения:
2020-02-15T15:25:26.111+0100|SEVERE: Exception while loading the app
2020-02-15T15:25:26.114+0100|SEVERE: Undeployment failed for context /restAppKt
2020-02-15T15:25:26.143+0100|SEVERE: Exception while loading the app : javax.ejb.CreateException: Initialization failed for Singleton SimpleRest
javax.ejb.CreateException: Initialization failed for Singleton SimpleRest
at com.sun.ejb.containers.AbstractSingletonContainer.createSingletonEJB(AbstractSingletonContainer.java:542)
at com.sun.ejb.containers.AbstractSingletonContainer.access$000(AbstractSingletonContainer.java:81)
at com.sun.ejb.containers.AbstractSingletonContainer$SingletonContextFactory.create(AbstractSingletonContainer.java:687)
at com.sun.ejb.containers.AbstractSingletonContainer.instantiateSingletonInstance(AbstractSingletonContainer.java:421)
at org.glassfish.ejb.startup.SingletonLifeCycleManager.initializeSingleton(SingletonLifeCycleManager.java:219)
at org.glassfish.ejb.startup.SingletonLifeCycleManager.initializeSingleton(SingletonLifeCycleManager.java:180)
at org.glassfish.ejb.startup.SingletonLifeCycleManager.doStartup(SingletonLifeCycleManager.java:158)
at org.glassfish.ejb.startup.EjbApplication.start(EjbApplication.java:169)
at org.glassfish.internal.data.EngineRef.start(EngineRef.java:123)
at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:280)
at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:344)
at com.sun.enterprise.v3.server.ApplicationLifecycle.initialize(ApplicationLifecycle.java:584)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:541)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:558)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:554)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:360)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:553)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:584)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:576)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:360)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:575)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1496)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1300(CommandRunnerImpl.java:120)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1878)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1754)
at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:564)
at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:251)
at org.glassfish.grizzly.http.server.StaticHttpHandlerBase.service(StaticHttpHandlerBase.java:166)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:520)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:217)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:182)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:156)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:218)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:95)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:260)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:177)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:109)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:88)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:53)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:524)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:89)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:94)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:33)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:114)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:569)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:549)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: Exception attempting to inject Remote ejb-ref name=eu.pstdio.restAppKt.SimpleRest/bean,Remote 3.x interface =eu.pstdio.restAppKt.BeanApi,ejb-link=null,lookup=,mappedName=,jndi-name=eu.pstdio.restAppKt.BeanApi,refType=Session into class eu.pstdio.restAppKt.SimpleRest: Lookup failed for 'java:comp/env/eu.pstdio.restAppKt.SimpleRest/bean' 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:194)
at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:46)
at org.jboss.weld.injection.producer.DefaultInjector.inject(DefaultInjector.java:73)
at org.jboss.weld.module.ejb.DynamicInjectionPointInjector.inject(DynamicInjectionPointInjector.java:61)
at org.jboss.weld.module.ejb.SessionBeanInjectionTarget.inject(SessionBeanInjectionTarget.java:138)
at org.glassfish.weld.services.JCDIServiceImpl$JCDIInjectionContextImpl.inject(JCDIServiceImpl.java:576)
at org.glassfish.weld.services.JCDIServiceImpl.injectEJBInstance(JCDIServiceImpl.java:323)
at com.sun.ejb.containers.BaseContainer.injectEjbInstance(BaseContainer.java:1796)
at com.sun.ejb.containers.AbstractSingletonContainer.createSingletonEJB(AbstractSingletonContainer.java:503)
... 48 more
Caused by: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Remote ejb-ref name=eu.pstdio.restAppKt.SimpleRest/bean,Remote 3.x interface =eu.pstdio.restAppKt.BeanApi,ejb-link=null,lookup=,mappedName=,jndi-name=eu.pstdio.restAppKt.BeanApi,refType=Session into class eu.pstdio.restAppKt.SimpleRest: Lookup failed for 'java:comp/env/eu.pstdio.restAppKt.SimpleRest/bean' 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:638)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:439)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:153)
at org.glassfish.weld.services.InjectionServicesImpl.aroundInject(InjectionServicesImpl.java:184)
... 56 more
Caused by: javax.naming.NamingException: Lookup failed for 'java:comp/env/eu.pstdio.restAppKt.SimpleRest/bean' 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=eu.pstdio.restAppKt.SimpleRest/bean,Remote 3.x interface =eu.pstdio.restAppKt.BeanApi,ejb-link=null,lookup=,mappedName=,jndi-name=eu.pstdio.restAppKt.BeanApi,refType=Session' . Actual (possibly internal) Remote JNDI name used for lookup is 'eu.pstdio.restAppKt.BeanApi#eu.pstdio.restAppKt.BeanApi' [Root exception is javax.naming.NamingException: Lookup failed for 'eu.pstdio.restAppKt.BeanApi#eu.pstdio.restAppKt.BeanApi' 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: eu.pstdio.restAppKt.BeanApi#eu.pstdio.restAppKt.BeanApi not found]]]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:496)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:561)
... 59 more
Caused by: javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=eu.pstdio.restAppKt.SimpleRest/bean,Remote 3.x interface =eu.pstdio.restAppKt.BeanApi,ejb-link=null,lookup=,mappedName=,jndi-name=eu.pstdio.restAppKt.BeanApi,refType=Session' . Actual (possibly internal) Remote JNDI name used for lookup is 'eu.pstdio.restAppKt.BeanApi#eu.pstdio.restAppKt.BeanApi' [Root exception is javax.naming.NamingException: Lookup failed for 'eu.pstdio.restAppKt.BeanApi#eu.pstdio.restAppKt.BeanApi' 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: eu.pstdio.restAppKt.BeanApi#eu.pstdio.restAppKt.BeanApi not found]]
at com.sun.ejb.EjbNamingReferenceManagerImpl.resolveEjbReference(EjbNamingReferenceManagerImpl.java:185)
at com.sun.enterprise.container.common.impl.ComponentEnvManagerImpl$EjbReferenceProxy.create(ComponentEnvManagerImpl.java:1015)
at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:770)
at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:738)
at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:159)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:476)
... 63 more
Caused by: javax.naming.NamingException: Lookup failed for 'eu.pstdio.restAppKt.BeanApi#eu.pstdio.restAppKt.BeanApi' 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: eu.pstdio.restAppKt.BeanApi#eu.pstdio.restAppKt.BeanApi not found]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:496)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at com.sun.ejb.EjbNamingReferenceManagerImpl.resolveEjbReference(EjbNamingReferenceManagerImpl.java:180)
... 68 more
Caused by: javax.naming.NameNotFoundException: eu.pstdio.restAppKt.BeanApi#eu.pstdio.restAppKt.BeanApi 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:70)
at com.sun.enterprise.naming.impl.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:114)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:483)
... 72 more
2020-02-15T15:26:04.645+0100|SEVERE: JNDI lookup failed for the resource: Name: java:module/env/eu.pstdio.restAppKt.SimpleRest/bean, Lookup: testBean, Type: Session.
2020-02-15T15:26:04.648+0100|SEVERE: JNDI lookup failed for the resource: Name: [java:module/env/eu.pstdio.restAppKt.SimpleRest/bean], Lookup: [testBean], Type: [Session]
2020-02-15T15:28:04.191+0100|SEVERE: JNDI lookup failed for the resource: Name: java:module/env/eu.pstdio.restAppKt.SimpleRest/bean, Lookup: testBean, Type: Session.
2020-02-15T15:28:04.192+0100|SEVERE: JNDI lookup failed for the resource: Name: [java:module/env/eu.pstdio.restAppKt.SimpleRest/bean], Lookup: [testBean], Type: [Session]
2020-02-15T15:30:25.724+0100|SEVERE: JNDI lookup failed for the resource: Name: java:module/env/eu.pstdio.restAppKt.SimpleRest/bean, Lookup: testBean, Type: Session.
2020-02-15T15:30:25.725+0100|SEVERE: JNDI lookup failed for the resource: Name: [java:module/env/eu.pstdio.restAppKt.SimpleRest/bean], Lookup: [testBean], Type: [Session]