簡體   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