以前的尝试是让Netbean将EJB模块部署到Netbean可以访问的Glassfish服务器上,该模块以JAR而不是EAR的形式构建。但是,通过CLI使用asadmin
将该JAR部署到Glassfish可能会遇到错误。
EAR通过CLI部署时没有问题--但是,EJB的JNDI名称似乎不起作用。差异是什么?
32.4.1.1可移植JNDI语法
三个JNDI名称空间用于可移植JNDI查找:java:global、java:module和java:app。
java:global JNDI名称空间是使用JNDI查找查找远程企业bean的可移植方式。JNDI地址的格式如下:java:global[/application name]/module name/enterprisebean name[/interface name]应用程序名称和模块名称默认为应用程序和模块的名称减去文件扩展名。仅当应用程序打包在EAR中时,才需要应用程序名称。仅当企业bean实现多个业务接口时,才需要接口名称。
http://docs.oracle.com/javaee/7/tutorial/doc/ejb-intro004.htm
查找这个bean的正确语法是什么?是java:global/HelloEAR/HelloEAR-ejb/greetings。欢迎BeanRemote
?我已经尝试了不止几个变种,但都没有成功。
部署应用程序:
thufir@dur:~$
thufir@dur:~$ glassfish-4.1/glassfish/bin/asadmin list-applications
HelloEAR <ear, ejb>
Command list-applications executed successfully.
thufir@dur:~$
thufir@dur:~$ glassfish-4.1/glassfish/bin/asadmin undeploy HelloEAR
Command undeploy executed successfully.
thufir@dur:~$
thufir@dur:~$ glassfish-4.1/glassfish/bin/asadmin list-applications
Nothing to list.
No applications are deployed to this target server.
Command list-applications executed successfully.
thufir@dur:~$
thufir@dur:~$ glassfish-4.1/glassfish/bin/asadmin deploy NetBeansProjects/HelloEAR/dist/HelloEAR.ear
Application deployed with name HelloEAR.
Command deploy executed successfully.
thufir@dur:~$
服务器。日志:
thufir@dur:~$
thufir@dur:~$ tail glassfish-4.1/glassfish/domains/domain1/logs/server.log -n 15
[2014-09-22T04:58:42.666-0700] [glassfish 4.1] [INFO] [AS-EJB-00055] [javax.enterprise.ejb.container] [tid: _ThreadID=650 _ThreadName=admin-listener(9)] [timeMillis: 1411387122666] [levelValue: 800] [[
Glassfish-specific (Non-portable) JNDI names for EJB GreetingsBean: [greetings.GreetingsBeanRemote#greetings.GreetingsBeanRemote, greetings.GreetingsBeanRemote]]]
[2014-09-22T04:58:43.619-0700] [glassfish 4.1] [WARN] [] [org.jboss.weld.Event] [tid: _ThreadID=650 _ThreadName=admin-listener(9)] [timeMillis: 1411387123619] [levelValue: 900] [[
WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.gf.cdi.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.]]
[2014-09-22T04:58:43.628-0700] [glassfish 4.1] [WARN] [] [org.jboss.weld.Event] [tid: _ThreadID=650 _ThreadName=admin-listener(9)] [timeMillis: 1411387123628] [levelValue: 900] [[
WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.]]
[2014-09-22T04:58:43.634-0700] [glassfish 4.1] [WARN] [] [org.jboss.weld.Event] [tid: _ThreadID=650 _ThreadName=admin-listener(9)] [timeMillis: 1411387123634] [levelValue: 900] [[
WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.]]
[2014-09-22T04:58:44.757-0700] [glassfish 4.1] [INFO] [] [javax.enterprise.system.core] [tid: _ThreadID=650 _ThreadName=admin-listener(9)] [timeMillis: 1411387124757] [levelValue: 800] [[
HelloEAR was successfully deployed in 2,312 milliseconds.]]
thufir@dur:~$
正在尝试查找:
thufir@dur:~$
thufir@dur:~$ glassfish-4.1/glassfish/bin/appclient -client NetBeansProjects/RemoteJNDI/dist/RemoteJNDI.jar
javax.naming.NamingException: Lookup failed for '[greetings.GreetingsBeanRemote' in SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, Context.SECURITY_CREDENTIALS=pass123, org.omg.CORBA.ORBInitialHost=localhost, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, Context.SECURITY_PRINCIPAL=user1} [Root exception is javax.naming.NameNotFoundException: [greetings.GreetingsBeanRemote 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 net.bounceme.dur.jndi.RemoteJNDI.main(RemoteJNDI.java:15)
Caused by: javax.naming.NameNotFoundException: [greetings.GreetingsBeanRemote 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.RemoteSerialContextProviderImpl.lookup(RemoteSerialContextProviderImpl.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie.dispatchToMethod(ReflectiveTie.java:143)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:173)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:1425)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2222)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)
thufir@dur:~$
如果您也在使用Maven,请检查应用程序ejb文件名末尾是否附加了“-1.0-SNAPSHOT”(或其他版本/根据您的应用程序)作为“application-ejb-1.0-SNAPSHOT”,全名为“java:global/application-ear/application-ejb-1.0-SNAPSHOT/fileName”
为什么调用bean时没有“java:”之类的东西?
成功:
thufir@dur:~$
thufir@dur:~$ glassfish-4.1/glassfish/bin/asadmin list-applications
Nothing to list.
No applications are deployed to this target server.
Command list-applications executed successfully.
thufir@dur:~$
thufir@dur:~$ glassfish-4.1/glassfish/bin/asadmin deploy NetBeansProjects/HelloEAR/dist/HelloEAR.ear
Application deployed with name HelloEAR.
Command deploy executed successfully.
thufir@dur:~$
thufir@dur:~$ glassfish-4.1/glassfish/bin/asadmin list-applications
HelloEAR <ear, ejb>
Command list-applications executed successfully.
thufir@dur:~$
thufir@dur:~$ glassfish-4.1/glassfish/bin/appclient -client NetBeansProjects/RemoteJNDI/dist/RemoteJNDI.jar
hello world
thufir@dur:~$
thufir@dur:~$
客户端代码:
package net.bounceme.dur.jndi;
import greetings.GreetingsBeanRemote;
import java.util.logging.Logger;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class RemoteJNDI {
private static final Logger log = Logger.getLogger(RemoteJNDI.class.getName());
public static void main(String... args) {
try {
InitialContext ctx = new InitialContext();
// Object obj = ctx.lookup("java:global/HelloEAR/HelloEAR-ejb/greetings.GreetingsBeanRemote");
Object obj = ctx.lookup("greetings.GreetingsBeanRemote");
GreetingsBeanRemote gbr = (GreetingsBeanRemote) obj;
System.out.println(gbr.hi());
} catch (NamingException ex) {
ex.printStackTrace();
}
}
}
ejb:
package greetings;
import javax.ejb.Stateless;
@Stateless
public class GreetingsBean implements GreetingsBeanRemote {
@Override
public String hi() {
return "hello world";
}
@Override
public String bye() {
return "bye";
}
}
接口:
package greetings;
import javax.ejb.Remote;
@Remote
public interface GreetingsBeanRemote {
public String hi();
public String bye();
}
服务器日志:
[2014-09-22T17:55:56.091-0700] [glassfish 4.1] [INFO] [] [javax.enterprise.system.tools.deployment.common] [tid: _ThreadID=40 _ThreadName=admin-listener(3)] [timeMillis: 1411433756091] [levelValue: 800] [[
visiting unvisited references]]
[2014-09-22T17:55:56.233-0700] [glassfish 4.1] [INFO] [AS-EJB-00054] [javax.enterprise.ejb.container] [tid: _ThreadID=40 _ThreadName=admin-listener(3)] [timeMillis: 1411433756233] [levelValue: 800] [[
Portable JNDI names for EJB GreetingsBean: [java:global/HelloEAR/HelloEAR-ejb/GreetingsBean!greetings.GreetingsBeanRemote, java:global/HelloEAR/HelloEAR-ejb/GreetingsBean]]]
[2014-09-22T17:55:56.235-0700] [glassfish 4.1] [INFO] [AS-EJB-00055] [javax.enterprise.ejb.container] [tid: _ThreadID=40 _ThreadName=admin-listener(3)] [timeMillis: 1411433756235] [levelValue: 800] [[
Glassfish-specific (Non-portable) JNDI names for EJB GreetingsBean: [greetings.GreetingsBeanRemote#greetings.GreetingsBeanRemote, greetings.GreetingsBeanRemote]]]
[2014-09-22T17:55:56.321-0700] [glassfish 4.1] [WARN] [] [org.jboss.weld.Event] [tid: _ThreadID=40 _ThreadName=admin-listener(3)] [timeMillis: 1411433756321] [levelValue: 900] [[
WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.]]
[2014-09-22T17:55:56.341-0700] [glassfish 4.1] [WARN] [] [org.jboss.weld.Event] [tid: _ThreadID=40 _ThreadName=admin-listener(3)] [timeMillis: 1411433756341] [levelValue: 900] [[
WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.]]
[2014-09-22T17:55:56.349-0700] [glassfish 4.1] [WARN] [] [org.jboss.weld.Event] [tid: _ThreadID=40 _ThreadName=admin-listener(3)] [timeMillis: 1411433756349] [levelValue: 900] [[
WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.gf.cdi.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.]]
[2014-09-22T17:55:56.819-0700] [glassfish 4.1] [INFO] [] [javax.enterprise.system.core] [tid: _ThreadID=40 _ThreadName=admin-listener(3)] [timeMillis: 1411433756819] [levelValue: 800] [[
HelloEAR was successfully deployed in 842 milliseconds.]]
thufir@dur:~$
我正在实现一个 JCA 入站资源适配器,以允许 EIS 将消息发送到部署在 Java EE 应用程序服务器上的应用程序。 应该只有使用我的注释进行了注释的EJB才是可访问的,所以我使用了一个javax . enterprise . inject . SPI . extension来观察ProcessAnnotatedType,然后我可以使用它来存储关于部署在应用服务器上的使用我的注释进行了注释的所
WebAssembly的二进制格式是被设计成可在不同操作系统与指令集上高效执行的,无论在Web或非Web环境中。 对高效执行的设想 尽管执行环境是有条件的,本地的,不确定的,也不要向WebAssembly提供下述特性。有些情况下为了WebAssembly模块执行,也许不得不模拟一些宿主硬件或操作系统不提供的特性,让它们似乎被支持。这种情况将会导致糟糕的性能。 随着WebAssembly的标准化推进
问题:似乎无法通过spring在Webphsere服务器中执行jndi查找EJB3。一直找不到我的jndi名称。我看不出我做错了什么。对于Websphere,您是否必须为jndi名称查找添加不同的内容? 堆栈溢出参考问题-EJB3注入Springbean 版本: Spring版本:4.1.2 WebSphereServer版本:7.0.0.27 Spring错误: 创建名为'myLocalEjb'
2.2.1.可移植性 Linux可以轻松地移植到各种不同的硬件平台上。有了Linux做硬件抽象层,Android就不必为不同硬件的兼容性而劳心。Linux 的绝大多数底层代码都是用可移植的 C 代码编写,因此第三方开发者可以将 Android 移植到很多不同的设备上。
"C语言结合了汇编的强大功能和可移植性" -- 无名氏,暗指比尔.萨克。 可移植代码的好处是有目共睹的。这一节将阐述一些编写可移植代码的指导原则。这里"可移植的"是指一个源码文件能够在不同机器上被编译和执行,其 前提仅仅是在不同平台上可能包含不同的头文件,使用不同的编译器开关选项罢了。头文件包含的#define和typedef可能因机器而异。一般 来说,一个新"机器"是指一种不同的硬件,一种不同的
我有两个非常简单的EAR文件。一个ear公开一个远程无状态ejb(称为server.ear),另一个ear是一个web模块加上一个查找远程ejb bean(client.ear)的本地ejb。通过@PostContStruct。 它们都被部署到在所有环境中运行Java7的Glassfish 3.1.2.2上的不同实例中。 它在本地机器上的容器环境中工作得非常好。我有两个不同的实例,并且能够成功地从