我在JBoss AS 7.2.0中使用Mobicents SipServlets 2.1.547。我需要将SipFactory注入到EJB中,并且使用@Resource批注,当我尝试访问SipFactory时,它总是会导致NullPointerException。此时,我的bean中有@Resource SipFactory sf
有什么理由为什么这行不通?注入SipFactory以便我可以从bean中访问它的正确方法是什么?

更新:我在@Resource批注中设置了映射名称,现在JBoss在部署时给了我以下错误:

JBAS014775:    New missing/unsatisfied dependencies:
  service jboss.naming.context.java.jboss.java:sip."com.mycompany.testproject.testapp".SipFactory (missing) dependents: [service jboss.naming.context.java.module.test."test-sip-1.0.0-SNAPSHOT".env."com.mycompany.testproject.testapp.ManagerBean".sf]


ManagerBean.java:

@Resource(mappedName="java:sip/com.mycompany.testproject.testapp/SipFactory")
private SipFactory sf;


sip.xml:

    <?xml version="1.0"?>
<sip-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jcp.org/xml/ns/sipservlet http://www.jcp.org/xml/ns/sipservlet/sip-app_1_1.xsd" version="1.1">
 <display-name>TEST SIP Servlet</display-name>
 <description>TEST SIP Servlet</description>
 <app-name>com.mycompany.testproject.testapp</app-name>

<servlet-selection>
    <main-servlet>
        TestServlet
    </main-servlet>
</servlet-selection>

 <servlet>
  <servlet-name>TestServlet</servlet-name>
  <servlet-class>com.mycompany.testproject.testapp.TestServlet</servlet-class>
  <init-param>
     <param-name>servertest</param-name>
     <param-value>sip:[email protected]:5080</param-value>
  </init-param>
        <load-on-startup>1</load-on-startup>
 </servlet>
 <session-config>
  <session-timeout>1</session-timeout>
 </session-config>
</sip-app>

最佳答案

您是否尝试设置映射名称?
与以下这段代码类似,您可以使用sip.xml部署描述符中的appname替换appname部分。

@Resource(mappedName="java:sip/appname/SipFactory")
private SipFactory sipFactoryResource;

07-25 23:18