查找邮件资源时,Glassfish会遇到无限循环。仅在定义自定义< module-name>时才会发生错误。在ejb.jar.xml中。
例外:
at javax.naming.InitialContext.lookup(InitialContext.java:392) at com.sun.enterprise.naming.util.JndiNamingObjectFactory.create(JndiNamingObjectFactory.java:90) 在com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:776) at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:744) at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:180) at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:498) at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455) 在javax.naming.InitialContext.lookup(InitialContext.java:392) 在javax.naming.InitialContext.lookup(InitialContext.java:392) at com.sun.enterprise.naming.util.JndiNamingObjectFactory.create(JndiNamingObjectFactory.java:90) 在com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:776) at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:744) at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:180) at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:498) at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455) 在javax.naming.InitialContext.lookup(InitialContext.java:392) 在javax.naming.InitialContext.lookup(InitialContext.java:392) at com.sun.enterprise.naming.util.JndiNamingObjectFactory.create(JndiNamingObjectFactory.java:90)
这是我的配置:
的glassfish-resources.xml中
<mail-resource enabled="true" host="${mail.host}"
jndi-name="mail/MailSession" object-type="user"
store-protocol="imap" store-protocol-class="com.sun.mail.imap.IMAPStore"
transport-protocol="smtp" transport-protocol-class="com.sun.mail.smtp.SMTPTransport"
user="mail@address.de" from="mail@address.de">
<property name="mail-smtp-auth" value="true"/>
<property name="mail-smtp-password" value="${password}" />
</mail-resource>
EMailService.java中的注入
...
@Resource(name = "java:module/mail/MailSession")
private Session mySession;
...
ejb.jar.xml
<module-name>backend</module-name>
当然,所有上面提到的文件都位于同一个模块中=&gt;后端。
使用JNDI-Internals的详细记录我可以将问题深入到以下几点:
工作场景(无模块名称): 如果没有特殊的模块名称,则模块名称将是带有文件扩展名的文件名,例如后端-1.1.1-快照。这将导致以下查找方案,最后重新启动MailResource:
.SerialContext; MethodName = lookup; | SerialContext ==&gt; lookup(java:module / mail / MailSession)|#] .SerialContext; MethodName = lookup; | SerialContext ==&gt;查找相对名称:java:module / mail / MailSession |#] .JavaURLContext; MethodName = lookup; |在javaURLContext.lookup中,name = java:module / mail / MailSession serialcontext ... null |#] .SerialContext; MethodName = lookup; | SerialContext ==&gt; lookup(java:global / portal-1.1.1 / backend-1.1.1-SNAPSHOT / mail / MailSession)|#] .SerialContext; MethodName = lookup; | SerialContext ==&gt;查找相对名称:java:global / portal-1.1.1 / backend-1.1.1-SNAPSHOT / mail / MailSession |#] .SerialContextProviderImpl;方法名=查找; | SerialContextProviderImpl :: lookup java:global / portal-1.1.1 / backend-1.1.1-SNAPSHOT / mail / MailSession |#] .GlassfishNamingManagerImpl; MethodName = lookup; | GlassfishNamingManager..null中的| serialcontext |#] .GlassfishNamingManagerImpl; MethodName = lookup; | GlassfishNamingManager:查找名称:java:module / mail / MailSession |#] .GlassfishNamingManagerImpl; MethodName = bindToNamespace; | naming.bind绑定名称:java:module / mail / MailSession |#]
ERROR SCENARIO(自定义模块名称): 添加如上面提到的ejb.jar.xml中所示的自定义模块名称将会带有无限循环的查找。
相关的查找日志记录如下所示:
FINE | glassfish3.1.1 | com.sun.enterprise.naming | _ThreadID = 23; _ThreadName = Thread-2; ClassName = com.sun.enterprise.naming.impl.SerialContext; MethodName = lookup; | SerialContext ==&gt ;查找相对名称:java:module / mail / MailSession |#] FINE | glassfish3.1.1 | com.sun.enterprise.naming | _ThreadID = 23; _ThreadName = Thread-2; ClassName = com.sun.enterprise.naming.impl.JavaURLContext; MethodName = lookup; | in javaURLContext.lookup,name = java:module / mail / MailSession serialcontext ... null |#] FINE | glassfish3.1.1 | com.sun.enterprise.naming | _ThreadID = 23; _ThreadName = Thread-2; ClassName = com.sun.enterprise.naming.impl.SerialContext; MethodName = lookup; | SerialContext ==&gt; lookup(java:global / private-ear-1.2.0-SNAPSHOT / backend / mail / MailSession)|#] FINE | glassfish3.1.1 | com.sun.enterprise.naming | _ThreadID = 23; _ThreadName = Thread-2; ClassName = com.sun.enterprise.naming.impl.SerialContext; MethodName = lookup; | SerialContext ==&gt;查找相对名称:java:global / private-ear-1.2.0-SNAPSHOT / backend / mail / MailSession |#] FINE | glassfish3.1.1 | com.sun.enterprise.naming | _ThreadID = 23; _ThreadName =螺纹-2;类名= com.sun.enterprise.naming.impl.SerialContextProviderImpl;方法名=查找; | SerialContextProviderImpl :: lookup java:global / private-ear-1.2.0-SNAPSHOT / backend / mail / MailSession |#] FINE | glassfish3.1.1 | com.sun.enterprise.naming | _ThreadID = 23; _ThreadName = Thread-2; ClassName = com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl; MethodName = lookup; | GlassfishNamingManager..null中的| serialcontext | #] FINE | glassfish3.1.1 | com.sun.enterprise.naming | _ThreadID = 23; _TreadName = Thread-2; ClassName = com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl; MethodName = lookup; | GlassfishNamingManager:查找名称:java :模块/邮件/邮件会话|#] FINE | glassfish3.1.1 | com.sun.enterprise.naming | _ThreadID = 23; _ThreadName = Thread-2; ClassName = com.sun.enterprise.naming.impl.SerialContext; MethodName = lookup; | SerialContext ==&gt; lookup(java:module / mail / MailSession)|#] FINE | glassfish3.1.1 | com.sun.enterprise.naming | _ThreadID = 23; _ThreadName = Thread-2; ClassName = com.sun.enterprise.naming.impl.SerialContext; MethodName = lookup; | SerialContext ==&gt;查找相对名称:java:module / mail / MailSession |#] FINE | glassfish3.1.1 | com.sun.enterprise.naming | _ThreadID = 23; _ThreadName = Thread-2; ClassName = com.sun.enterprise.naming.impl.JavaURLContext; MethodName = lookup; | in javaURLContext.lookup,name = java:module / mail / MailSession serialcontext ... null |#] FINE | glassfish3.1.1 | com.sun.enterprise.naming | _ThreadID = 23; _ThreadName = Thread-2; ClassName = com.sun.enterprise.naming.impl.SerialContext; MethodName = lookup; | SerialContext ==&gt; lookup(java:global / private-ear-1.2.0-SNAPSHOT / backend / mail / MailSession)|#] FINE | glassfish3.1.1 | com.sun.enterprise.naming | _ThreadID = 23; _ThreadName = Thread-2; ClassName = com.sun.enterprise.naming.impl.SerialContext; MethodName = lookup; | SerialContext ==&gt;查找相对名称:java:global / private-ear-1.2.0-SNAPSHOT / backend / mail / MailSession |#] FINE | glassfish3.1.1 | com.sun.enterprise.naming | _ThreadID = 23; _ThreadName =螺纹-2;类名= com.sun.enterprise.naming.impl.SerialContextProviderImpl;方法名=查找; | SerialContextProviderImpl :: lookup java:global / private-ear-1.2.0-SNAPSHOT / backend / mail / MailSession |#] FINE | glassfish3.1.1 | com.sun.enterprise.naming | _ThreadID = 23; _ThreadName = Thread-2; ClassName = com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl; MethodName = lookup; | GlassfishNamingManager..null中的| serialcontext | #] FINE | glassfish3.1.1 | com.sun.enterprise.naming | _ThreadID = 23; _TreadName = Thread-2; ClassName = com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl; MethodName = lookup; | GlassfishNamingManager:查找名称:java :模块/邮件/邮件会话|#] FINE | glassfish3.1.1 | com.sun.enterprise.naming | _ThreadID = 23; _ThreadName = Thread-2; ClassName = com.sun.enterprise.naming.impl.SerialContext; MethodName = lookup; | SerialContext ==&gt; lookup(java:module / mail / MailSession)|#] FINE | glassfish3.1.1 | com.sun.enterprise.naming | _ThreadID = 23; _ThreadName = Thread-2; ClassName = com.sun.enterprise.naming.impl.SerialContext; MethodName = lookup; | SerialContext ==&gt;查找相对名称:java:module / mail / MailSession |#] FINE | glassfish3.1.1 | com.sun.enterprise.naming | _ThreadID = 23; _ThreadName = Thread-2; ClassName = com.sun.enterprise.naming.impl.JavaURLContext; MethodName = lookup; | in javaURLContext.lookup,name = java:module / mail / MailSession serialcontext ... null |#] FINE | glassfish3.1.1 | com.sun.enterprise.naming | _ThreadID = 23; _ThreadName = Thread-2; ClassName = com.sun.enterprise.naming.impl.SerialContext; MethodName = lookup; | SerialContext ==&gt; lookup(java:global / private-ear-1.2.0-SNAPSHOT / backend / mail / MailSession)|#] FINE | glassfish3.1.1 | com.sun.enterprise.naming | _ThreadID = 23; _ThreadName = Thread-2; ClassName = com.sun.enterprise.naming.impl.SerialContext; MethodName = lookup; | SerialContext ==&gt;查找相对名称:java:global / private-ear-1.2.0-SNAPSHOT / backend / mail / MailSession |#]
从asadmin手动检查glassfish资源会获取以下条目:
private-ear-1.2.0-SNAPSHOT <ear, web, ejb>
private-frontend-1.2.0-SNAPSHOT.war <WebModule>
backend-1.2.0-SNAPSHOT.jar <EJBModule>
java:module/mail/MailSession <MailResource>
如果那里有专家,请给我一个提示。