我在访问无状态会话bean属性时遇到了一些问题。这些是我到目前为止所尝试过的。请详细说明我所缺少的内容。
我在IBM WAS 8.5中将名称空间绑定为global / env
我有我的ejb:
@Singleton
@Stateless(mappedName="envEJB")
@LocalBean
@ConcurrencyManagement
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public class EnvEJB {
@Resource(lookup="global/env")
protected String env;
@Lock(LockType.READ)
@AccessTimeout(1000)
public String getEnv() {
return env;
}
我正在尝试访问我的主要课程:
Hashtable<String, String> env = new Hashtable<String, String>();
pdEnv.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
pdEnv.put(Context.PROVIDER_URL, "iiop://localhost:2890");
String str = "java:comp/env/envEJB";
Context context = new InitialContext(env);
EnvironmentEJB ejb = (EnvironmentEJB) context.lookup(str);
我在这里尝试实现的只是尝试从服务器访问一些名称空间绑定。
执行以上呼叫我正在
javax.naming.ConfigurationException: Name space accessor for the java: name space has not been set. Possible cause is that the user is specifying a java: URL name in a JNDI Context method call but is not running in a J2EE client or server environment.
调用String str = "java:app/appname/envEJB";
给了我同样的错误。
更新
做为
Hashtable<String, String> pdEnv = new Hashtable<String, String>();
pdEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
pdEnv.put(Context.PROVIDER_URL, "iiop://localhost:2890");
Context context = new InitialContext(pdEnv);
java.lang.Object ejbBusIntf = context.lookup("com.test.EnvironmentEJBRemote");
EnvironmentEJB ejb = (EnvironmentEJB)javax.rmi.PortableRemoteObject.narrow(ejbBusIntf, EnvironmentEJB.class);
发生以下异常
Exception in thread "P=925268:O=0:CT" java.lang.ClassCastException: cannot cast class org.omg.stub.java.rmi._Remote_Stub to class com.test.EnvironmentEJB
at com.ibm.rmi.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:396)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:148)
at com.test.Test.main(Test.java:43)
答案 0 :(得分:1)
java:
命名空间仅在托管环境(应用程序服务器或应用程序客户端)中受支持。瘦客户端(独立Java SE主类)不支持它们。为此,您需要使用非java:
名称。请参阅SystemOut.log中的CNTR0167I
消息,以查找非java:
绑定。