我正在使用 Mobicents SipServlets 2.1.547 和 JBoss AS 7.2.0。我需要将 SipFactory 注入到 EJB 中,并且我正在使用 @Resource 注释,当我尝试访问 SipFactory 时总是会导致 NullPointerException。在这一点上@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:siptest@127.0.0.1:5080</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<session-config>
<session-timeout>1</session-timeout>
</session-config>
</sip-app>