dangdangdotcom / dubbox

Dubbox now means Dubbo eXtensions, and it adds features like RESTful remoting, Kyro/FST serialization, etc to the Dubbo service framework.
http://dangdangdotcom.github.io/dubbox
Apache License 2.0
4.89k stars 2.06k forks source link

dubbo REST添加扩展的filter时,如何注入Spring中的Bean ? #249

Open sunxboy opened 7 years ago

sunxboy commented 7 years ago
<dubbo:protocol name="rest" port="${dubbo.protocol.rest.port}" threads="500" contextpath="rest" server="tomcat" accepts="500" extension="com.pip.rest.serv.extension.AuthenticationTraceFilter"/>

如上配置,添加了一个扩展,AuthenticationTraceFilter 分别实现了ContainerRequestFilter,ContainerResponseFilter接口。 我想在AuthenticationTraceFilter引入spring中的其它对象,怎么做?@Autowired注解试过了,不行。

sunxboy commented 7 years ago
@Priority(900)
@PreMatching
@Provider
public class AuthenticationTraceFilter implements ContainerRequestFilter, ContainerResponseFilter {

    @Context
    private HttpServletRequest httpRequest;
    @Autowired
    private MyService service;
 ...........
}
cdToucher commented 6 years ago

static { userService = BeanContext.getBean(UserService.class); applicationDao = BeanContext.getBean(ApplicationDao.class); } public class BeanContext implements ApplicationContextAware