邮件会话资源JNDI查找中Jetty 9中的NameNotfoundException [英] NameNotfoundException in Jetty 9 at mail session resource JNDI lookup

查看:113
本文介绍了邮件会话资源JNDI查找中Jetty 9中的NameNotfoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm writing a REST API backend servlet with Jersey, and I have some problems using jndi to configure mail sending.

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

Here's my 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>

这是我尝试查找的方法:

And here's how I try to look it up:

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)

从服务码头重启"之后的DEBUG日志中:

From the DEBUG logs after 'service jetty restart':

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

因此应该绑定.我在这里想念什么?

So it should be bound. What am I missing here?

推荐答案

有2件事情需要您解决.

There's 2 things for you to fix.

首先,您的DOCTYPE错误.

First, Your DOCTYPE is bad.

应该是

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

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

Second, you seem to be missing the mandatory WEB-INF/web.xml reference to your JNDI object.

添加此内容:

<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

Also note, that for this to work on Jetty 9.2+ you'll want the the annotations and jndi modules enabled in your ${jetty.base}/start.ini

这篇关于邮件会话资源JNDI查找中Jetty 9中的NameNotfoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆