有关Spring如何设置和使用CXF拦截器的问题。我想将传入的SOAP请求记录到数据库以获取审计日志。我有如下设置,但每当传入的SOAP请求到来时,我都会获得正在访问服务层类的NPE。它从日志中查看Web应用程序上下文再次被重新加载导致服务bean的空引用。 我查看了两个条目 - this和this - 它们很接近,并在第一个链接中尝试了解决方案,但没有工作。 任何帮助表示赞赏。
由于
拦截器代码:
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 :(得分:0)
我希望您获得CXFServlet上下文和ContextLoaderListener中包含的/WEB-INF/cxf-servlet.xml
内容。尝试从ContextLoaderListener的contextConfigLocation属性中删除行/WEB-INF/cxf-servlet.xml
。您还应重命名cxf-servlet.xml
,因为CXFServlet会查找具有该确切名称的文件(请参阅http://cxf.apache.org/docs/configuration.html) - 或将其合并到applicationContext.xml
的其余部分。