簡體   English   中英

如何在CXF攔截器上下文中使用@Inject或@EJB?

[英]How to use @Inject or @EJB in a CXF interceptor context?

有沒有辦法在CXF攔截器中使用@Inject或@EJB? 我知道我仍然可以進行JNDI查找,但我寧願避免它。

我發現管理JAX-WS處理程序但CXF攔截器不是很奇怪。 是否可以管理它們? 我正在使用注釋將我的攔截器添加到端點( @org.apache.cxf.interceptor.InInterceptors@org.apache.cxf.interceptor.InInterceptors ),是否可以使用配置文件進行處理?

組態:

  • Java 6
  • JBoss EAP 6.1(AS 7.2)
  • CXF 2.6.6

我已經在CDI 1.1的幫助下注射了如下。

beans.xml中

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
      http://java.sun.com/xml/ns/javaee 
      http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>

CXF-servlet.xml中

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cxf="http://cxf.apache.org/core"
    xsi:schemaLocation="
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="callerInfoInterceptor" class="my.CallerInfoInterceptor" />

    <cxf:bus>
        <cxf:inInterceptors>
            <ref bean="callerInfoInterceptor" />
        </cxf:inInterceptors>
        <cxf:properties>
            ......
            .....
        </cxf:properties>
    </cxf:bus>

</beans>

CallerInfoInterceptor.java(CXF攔截器)

public class CallerInfoInterceptor extends AbstractPhaseInterceptor<Message>  {

    @Inject CallerInfoBean callerInfo; // bean

    public CallerInfoInterceptor() {
        super(Phase.RECEIVE);
    }

    @Override
    public void handleMessage(Message message){
     ...........

     if (callerInfo == null) {
            callerInfo =  
          javax.enterprise.inject.spi.CDI.current().select(CallerInfoBean.class).get();
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM