我已經在Wildfly中部署了一個名爲User Data的模塊和一個會話Bean的EJB3應用程序。 這是我的項目結構: 無法從客戶端應用程序獲取Bean
這是的UserData狀態bean:
@Stateful
@Remote(UserDataRemote.class)
public class UserData implements UserDataRemote, UserDataLocal {
private String name;
/**
* Default constructor.
*/
public UserData() {
// TODO Auto-generated constructor stub
}
@Override
public void saveName(String name) {
// TODO Auto-generated method stub
this.name =name;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return this.name;
}
}
這是控制檯的作物:
這是我在嘗試通過JNDI從應用程序中檢索它:
public static void main (String args[]) {
Properties jndiProperties = new Properties();
jndiProperties.put("jboss.naming.client.ejb.context", true);
jndiProperties.put(Context.PROVIDER_URL, "http-remoting://127.0.0.1:8080");
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
try {
InitialContext namingContext = new InitialContext(jndiProperties);
UserDataRemote userRemote = (UserDataRemote)namingContext.lookup("java:global/testEJB/UserData!entities.UserDataRemote");
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
**更新** 我也嘗試使用這個網址查詢:
UserDataRemote userRemote = (UserDataRemote)namingContext.lookup("ejb:/testEJB//UserData!entities.UserDataRemote?stateful");
但它無法找到它。
這是我的錯誤:
ott 06, 2017 7:45:51 AM org.xnio.Xnio <clinit>
INFO: XNIO version 3.4.0.Final
ott 06, 2017 7:45:51 AM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.4.0.Final
ott 06, 2017 7:45:51 AM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 4.0.21.Final
ott 06, 2017 7:45:52 AM org.jboss.ejb.client.remoting.VersionReceiver handleMessage
INFO: EJBCLIENT000017: Received server version 2 and marshalling strategies [river]
ott 06, 2017 7:45:52 AM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate
INFO: EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{[email protected], receiver=Remoting connection EJB receiver [connection=Remoting connection <13359fd6> on endpoint "config-based-naming-client-endpoint" <6536e911>,channel=jboss.ejb,nodename=macbook-pro-di-andrea]} on channel Channel ID 96d8a7d7 (outbound) of Remoting connection 1f36e637 to /127.0.0.1:8080 of endpoint "config-based-naming-client-endpoint" <6536e911>
javax.naming.NameNotFoundException: global/testEJB/UserData!entities.UserDataRemote -- service jboss.naming.context.java.jboss.exported.global.testEJB."UserData!entities.UserDataRemote"
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:106)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:207)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:184)
at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:127)
at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
區分EAR或JAR文件中的部署很重要。但沒有領先的「ejb:」我無法訪問我的豆。 – jaysee
看看這裏的一個工作示例:https:// github。com/simasch/jbosseap7ejbdemo –