Vir*_*nie 6 java dependency-injection cxf jax-ws
有没有办法在CXF拦截器中使用@Inject或@EJB?我知道我仍然可以进行JNDI查找,但我宁愿避免它.
我发现管理JAX-WS处理程序但CXF拦截器不是很奇怪.是否可以管理它们?我正在使用注释将我的拦截器添加到端点(@org.apache.cxf.interceptor.InInterceptors和@org.apache.cxf.interceptor.InInterceptors),是否可以使用配置文件进行处理?
组态:
我在 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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
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();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
615 次 |
| 最近记录: |