EJB をルックアップする方法はいくつかあります
このルックアップを使用して ejb サーバーに接続できますが、ConsoleClient を使用する場合のみです。
"ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName)
Tomcat アプリケーション サーバー (Spring MVC プロジェクト) でこのルックアップを試みると、このルックアップは機能しません。Jboss は ClassNotFoundException で応答します。
別のjndiルックアップ名が必要だと思いますか? 残念ながら、ウェブ上で役立つ情報を見つけることができませんでした。
編集:
私のコントローラー
@RequestMapping(value = "login", method = RequestMethod.POST)
public LoginBeanRemote logIn(){
final Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
Context context = null;
try {
context = new InitialContext(jndiProperties);
} catch (NamingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
final String appName = "foo_business";
final String moduleName = "foo_business";
final String distinctName = "";
final String beanName = "LoginBean";
// gesucht ist die klasse vom jboss , nicht die im frontend
final String viewClassName = "foo.business.login.LoginBeanRemote";
System.out.println("Looking EJB via JNDI ");
System.out.println("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);
try {
return (LoginBeanRemote) context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
春のプロジェクトのルートフォルダーに jboss-ejb-client.properties ファイルを配置しました
endpoint.name=foo_business //プロジェクト名
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=デフォルト
remote.connection.default.host=127.0.0.1
remote.connection.default.port= 4447
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
LoginBean の最初の部分 (JBOSS に JAR ファイルとしてデプロイされます。
@Stateful
@Remote(LoginBeanRemote.class)
public class LoginBean implements LoginBeanRemote {
生成された EJB ルックアップ名:
ejb:foo_business/foo_business//LoginBean!foo.business.login.LoginBeanRemote
エラー:
javax.naming.NamingException: Could not load ejb proxy class recc.business.login.LoginBeanRemote [Root exception is java.lang.ClassNotFoundException: recc.business.login.LoginBeanRemote]
at org.jboss.ejb.client.naming.ejb.EjbNamingContext.createEjbProxy(EjbNamingContext.java:108)
at org.jboss.ejb.client.naming.ejb.EjbNamingContext.lookup(EjbNamingContext.java:96)
at javax.naming.InitialContext.lookup(Unknown Source)
at recc.frontend.controller.UserController.logIn(UserController.java:161)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: recc.business.login.LoginBeanRemote
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.jboss.ejb.client.naming.ejb.EjbNamingContext.createEjbProxy(EjbNamingContext.java:106)
... 36 foo
編集:
クラスパスに ejb-project.jar を追加しました。また、春のプロジェクトに ejb パッケージを追加し、そこに置きましLoginBeanRemote
た。
これまでのところ、プロジェクトは ClassNotFound エラーで応答しません。作成した LoginBeanRemote をデバッグすると、次の内容が含まれます。
Proxy for remote EJB StatelessEJBLocator{appName='foo_business', moduleName='foo_business', distinctName='', beanName='LoginBean', view='interface foo.business.login.LoginBeanRemote'}
ルックアップ中に例外はありません。
LoginBeanRemote remote = (LoginBeanRemote) context.lookup("ejb:"
+ appName + "/" + moduleName + "/" + distinctName + "/"
+ beanName + "!" + viewClassName);
return remote;
Bean の関数を呼び出そうとすると、例外が発生します
System.out.println(remote.helloBean());
メッセージ全文:
Aug 30, 2013 11:26:21 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [appServlet] in context with path [/test] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: No EJB receiver available for handling [appName:foo_business,modulename:foo_business,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@c7c0866] with root cause
java.lang.IllegalStateException: No EJB receiver available for handling [appName:foo_business,modulename:foo_business,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@c7c0866
at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:584)
at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:119)
at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
at com.sun.proxy.$Proxy10.helloBean(Unknown Source)
at foo.frontend.controller.UserController.logIn(UserController.java:167)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
編集: JBoss をシャットダウンしたところ、同じエラーが表示されました。Jbossとはまったく関係がないと思います。
編集:
コードを更新しました:
InitialContext context = null;
try {
final Properties initialContextProperties = new Properties();
initialContextProperties.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.naming.remote.client.InitialContextFactory");
initialContextProperties.put(Context.PROVIDER_URL,
"remote://localhost:4447");
initialContextProperties.put(Context.URL_PKG_PREFIXES,
"org.jboss.ejb.client.naming");
initialContextProperties
.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT",
"false");
initialContextProperties.put(Context.SECURITY_PRINCIPAL, "myapplicationrealmuser");
initialContextProperties
.put(Context.SECURITY_CREDENTIALS, "mypass");
EJBClientConfiguration cc = new PropertiesBasedEJBClientConfiguration(
initialContextProperties);
ContextSelector<EJBClientContext> selector = new ConfigBasedEJBClientContextSelector(
cc);
EJBClientContext.setSelector(selector);
context = new InitialContext(initialContextProperties);
} catch (NamingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("Looking EJB via JNDI ");
try {
LoginBeanRemote remote = (LoginBeanRemote) context
.lookup("java:global/foo_business/LoginBean!foo.business.login.LoginBeanRemote");
System.out.println(remote.helloBean());
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
これにより、ルックアップ中に NameNotFoundException が返されます。あらゆる種類のルックアップ名を試しましたが、このようには機能しません。いくつかの構成がありませんか?
エラー:
javax.naming.NameNotFoundException: global/foo_business/LoginBean!foo.business.login.LoginBeanRemote -- service jboss.naming.context.java.jboss.exported.global.foo_business."LoginBean!foo.business.login.LoginBeanRemote"
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
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(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
JBOSS コンソール JNDI 情報:
編集:
EJB を EAR ファイルとしてデプロイしましたが、同じ例外が引き続き発生します
javax.naming.NameNotFoundException: global/foo_business_ear-ear/foo_business_ear-ejb/LoginBean!foo.business.login.LoginBeanRemote -- service jboss.naming.context.java.jboss.exported.global.foo_business_ear-ear.foo_business_ear-ejb."LoginBean!foo.business.login.LoginBeanRemote"
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
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(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
ERROR: org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1 - Channel end notification received, closing channel Channel ID ef1b671f (outbound) of Remoting connection 6af39445 to localhost/127.0.0.1:4447