首页 文章

@Autowired不在CXF拦截器Spring应用程序中工作

提问于
浏览
2

有关Spring如何设置和使用CXF拦截器的问题 . 我想将传入的SOAP请求记录到数据库以获取审计日志 . 我有如下设置,但每当传入的SOAP请求到来时,我都会获得正在访问服务层类的NPE . 它从日志中查看Web应用程序上下文再次被重新加载导致服务bean的空引用 . 我看了两个条目 - thisthis - 它们很接近,并在第一个链接中尝试了解决方案,但没有工作 . 任何帮助表示赞赏 .

谢谢

Interceptor code:

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>

1 回答

  • 0

    我希望您在CXFServlet 's context and the 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 的其余部分中 .

相关问题