2013-11-27 52 views
2

在CXF攔截器如何由Spring設置和使用方面存在問題。我想將傳入的SOAP請求記錄到數據庫以用於審計日誌。我有如下設置,但每當傳入SOAP請求時,我都會得到正在訪問服務層類的NPE。它從日誌中看到Web應用程序上下文正在被重新加載,導致服務bean的空引用。 我查看了兩個條目 - thisthis - 這兩個條目都很接近,並試用了第一個鏈接中的解決方案,但無法正常工作。 任何幫助表示讚賞。@Exutow不適用於CXF攔截器+ Spring應用程序

由於

攔截代碼:

public class AuditLogInterceptor extends AbstractLoggingInterceptor { 

private AuditLogService auditLogService; 

@Autowired 
public void setAuditLogService(AuditLogService auditLogService) { 
    this.auditLogService = auditLogService; 
} 
private void saveAuditLogEntry() { 
    // some more code ... 
    auditLogService.logRequest(logEntry); 
} 

的cxf-servlet.xml中

<import resource="classpath:META-INF/cxf/cxf.xml" /> 
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> 
<bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" /> 

<!-- Add new endpoints for additional services you'd like to expose --> 
<bean id="abstractLogInterceptor" abstract="true"> 
    <property name="prettyLogging" value="true" /> 
</bean> 
<bean class="com.xyz.interceptor.AuditLogInterceptor" id="logInInterceptor" parent="abstractLogInterceptor"/> 

<jaxws:endpoint id="dataService" implementor="#masterDataService" address="/MasterDataService"> 
    <jaxws:inInterceptors> 
     <ref bean="logInInterceptor" /> 
    </jaxws:inInterceptors> 
</jaxws:endpoint> 

web.xml中

<context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
      classpath:/applicationContext-resources.xml 
      classpath:/applicationContext-dao.xml 
      classpath:/applicationContext-service.xml 
      classpath*:/applicationContext.xml 
      /WEB-INF/applicationContext*.xml 
      /WEB-INF/cxf-servlet.xml 
      /WEB-INF/security.xml 
     </param-value> 
</context-param> 
<listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 
    <listener> 
     <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class> 
    </listener> 
    <listener> 
     <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> 
    </listener> 
<servlet> 
    <servlet-name>CXFServlet</servlet-name> 
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> 
</servlet> 
<servlet-mapping> 
    <servlet-name>CXFServlet</servlet-name> 
    <url-pattern>/services/*</url-pattern> 
</servlet-mapping> 
+0

您有一個名爲'cxf-servlet.xml'的bean配置文件,它導入一個名爲'cxf-servlet.xml'的文件?可能不是你的問題的原因,但肯定會令人困惑 – artbristol

+0

你可以添加你的web.xml中的提取以及你有的其他任何spring配置文件嗎? '@ Autowired'在其他bean上工作嗎? – artbristol

+0

上面的cxf-servlet.xml存在於我的Web應用程序中,它包含的cxf-servlet.xml是CXF文件。將web.xml添加到問題。是的,@Autowired適用於其他組件,比如Spring MVC控制器 – Pragmatic

回答

0

我希望你得到的/WEB-INF/cxf-servlet.xml列入CXFServlet的上下文和的ContextLoaderListener的兩個內容。嘗試從ContextLoaderListener的contextConfigLocation屬性中刪除行/WEB-INF/cxf-servlet.xml。您還應該重命名cxf-servlet.xml,因爲CXFServlet將查找具有該確切名稱的文件(請參閱http://cxf.apache.org/docs/configuration.html) - 或將其合併到applicationContext.xml的其餘部分。