繁体   English   中英

邮件会话资源JNDI查找中Jetty 9中的NameNotfoundException

[英]NameNotfoundException in Jetty 9 at mail session resource JNDI lookup

我正在使用Jersey编写REST API后端servlet,使用jndi配置邮件发送时遇到一些问题。

这是我的WEB-INF / jetty-env.xml:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
  <New id="mail" class="org.eclipse.jetty.plus.jndi.Resource">
    <Arg><Ref refid="wac"/></Arg>
    <Arg>mail/Session</Arg>
    <Arg>
      <New class="org.eclipse.jetty.jndi.factories.MailSessionReference">
        <Set name="user">MY_USER</Set>
        <Set name="password">MY_PASS</Set>
        <Set name="properties">
          <New class="java.util.Properties">
            <Put name="mail.smtp.host">MY_HOST</Put>
            <Put name="mail.from">MY_SENDER</Put>
            <Put name="mail.debug">true</Put>
          </New>
        </Set>
      </New>
    </Arg>
  </New>
</Configure>

这是我尝试查找的方法:

Session session = (Session) new InitialContext().lookup("java:comp/env/mail/Session");

但是,我得到:

 javax.naming.NameNotFoundException; remaining name 'mail/Session'
at org.eclipse.jetty.jndi.local.localContextRoot.lookup(localContextRoot.java:487)

从“服务码头重启”之后的调试日志中:

20-01-2015 10:10:39 DEBUG jndi:183 - SAVE mail/Session in o.e.j.w.WebAppContext@4b9e13df{/finalcountdown.backend,file:/tmp/jetty-0.0.0.0-8085-finalcountdown.backend.war-_finalcountdown.backend-any-2063340985085206547.dir/webapp/,STARTING}{/finalcountdown.backend.war}
20-01-2015 10:10:39 DEBUG jndi:79 - InitialContextFactory.getInitialContext()
20-01-2015 10:10:39 DEBUG jndi:82 - Created initial context delegate for local namespace:org.eclipse.jetty.jndi.local.localContextRoot@6b9651f3
20-01-2015 10:10:39 DEBUG jndi:79 - InitialContextFactory.getInitialContext()
20-01-2015 10:10:39 DEBUG jndi:82 - Created initial context delegate for local namespace:org.eclipse.jetty.jndi.local.localContextRoot@23d2a7e8
20-01-2015 10:10:39 DEBUG jndi:411 - Looking up name="org.eclipse.jetty.webapp.WebAppContext@4b9e13df"
20-01-2015 10:10:39 DEBUG jndi:137 - supportDeepBinding=false
20-01-2015 10:10:39 DEBUG jndi:1280 - Adding binding with key=org.eclipse.jetty.webapp.WebAppContext@4b9e13df obj=org.eclipse.jetty.jndi.NamingContext@4abdb505[name=org.eclipse.jetty.webapp.WebAppContext@4b9e13df,parent=org.eclipse.jetty.jndi.local.localContextRoot$NamingRoot@7ce6a65d,bindings.size=0] for context=null as org.eclipse.jetty.webapp.WebAppContext@4b9e13df: org.eclipse.jetty.jndi.NamingContext:org.eclipse.jetty.jndi.NamingContext@4abdb505[name=org.eclipse.jetty.webapp.WebAppContext@4b9e13df,parent=org.eclipse.jetty.jndi.local.localContextRoot$NamingRoot@7ce6a65d,bindings.size=0]
20-01-2015 10:10:39 DEBUG jndi:82 - Subcontext org.eclipse.jetty.webapp.WebAppContext@4b9e13df created
20-01-2015 10:10:39 DEBUG jndi:464 - Looking up name="__"
20-01-2015 10:10:39 DEBUG jndi:137 - supportDeepBinding=false
20-01-2015 10:10:39 DEBUG jndi:1280 - Adding binding with key=__ obj=org.eclipse.jetty.jndi.NamingContext@1500955a[name=__,parent=org.eclipse.jetty.jndi.NamingContext@4abdb505,bindings.size=0] for context=org.eclipse.jetty.webapp.WebAppContext@4b9e13df as __: org.eclipse.jetty.jndi.NamingContext:org.eclipse.jetty.jndi.NamingContext@1500955a[name=__,parent=org.eclipse.jetty.jndi.NamingContext@4abdb505,bindings.size=0]
20-01-2015 10:10:39 DEBUG jndi:82 - Subcontext __ created
20-01-2015 10:10:39 DEBUG jndi:464 - Looking up name="mail"
20-01-2015 10:10:39 DEBUG jndi:137 - supportDeepBinding=false
20-01-2015 10:10:39 DEBUG jndi:1280 - Adding binding with key=mail obj=org.eclipse.jetty.jndi.NamingContext@e874448[name=mail,parent=org.eclipse.jetty.jndi.NamingContext@1500955a,bindings.size=0] for context=__ as mail: org.eclipse.jetty.jndi.NamingContext:org.eclipse.jetty.jndi.NamingContext@e874448[name=mail,parent=org.eclipse.jetty.jndi.NamingContext@1500955a,bindings.size=0]
20-01-2015 10:10:39 DEBUG jndi:82 - Subcontext mail created
20-01-2015 10:10:39 DEBUG jndi:1327 - Removing binding with key=Session
20-01-2015 10:10:39 DEBUG jndi:1280 - Adding binding with key=Session obj=mail/Session for context=mail as Session: org.eclipse.jetty.plus.jndi.Resource:mail/Session
20-01-2015 10:10:39 DEBUG jndi:88 - Bound object to Session
20-01-2015 10:10:39 DEBUG jndi:411 - Looking up name="org.eclipse.jetty.webapp.WebAppContext@4b9e13df"
20-01-2015 10:10:39 DEBUG jndi:76 - Subcontext org.eclipse.jetty.webapp.WebAppContext@4b9e13df already exists
20-01-2015 10:10:39 DEBUG jndi:464 - Looking up name="mail"
20-01-2015 10:10:39 DEBUG jndi:137 - supportDeepBinding=false
20-01-2015 10:10:39 DEBUG jndi:1280 - Adding binding with key=mail obj=org.eclipse.jetty.jndi.NamingContext@29b5cd00[name=mail,parent=org.eclipse.jetty.jndi.NamingContext@4abdb505,bindings.size=0] for context=org.eclipse.jetty.webapp.WebAppContext@4b9e13df as mail: org.eclipse.jetty.jndi.NamingContext:org.eclipse.jetty.jndi.NamingContext@29b5cd00[name=mail,parent=org.eclipse.jetty.jndi.NamingContext@4abdb505,bindings.size=0]
20-01-2015 10:10:39 DEBUG jndi:82 - Subcontext mail created
20-01-2015 10:10:39 DEBUG jndi:1327 - Removing binding with key=Session
20-01-2015 10:10:39 DEBUG jndi:1280 - Adding binding with key=Session obj=Reference Class Name: javax.mail.Session

因此,它应该受到约束。 我在这里想念什么?

有两件事需要您解决。

首先,您的DOCTYPE不好。

它应该是

<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">

其次,您似乎缺少对JNDI对象的强制性WEB-INF/web.xml引用。

添加:

<resource-ref>
  <res-ref-name>mail/Session</res-ref-name>
  <res-type>javax.mail.Session</res-type>
  <res-auth>Container</res-auth>
</resource-ref>

那应该让你的环境快乐

另请注意,要在Jetty 9.2+上运行此功能,您${jetty.base}/start.ini${jetty.base}/start.ini启用annotationsjndi模块。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM