开发者

How do I Spring enable a Tomcat valve

I wrote a Tomcat valve and configured it in server.xml. So far so good. However, I want one of the valve's data members to be a Spring managed bean. So, how can I make the valve 开发者_如何学运维also be Spring managed so that I can have Spring's IoC inject that dependency into the valve?


Valves aren't associated with an application, while spring contexts are. So you can't have a spring-managed bean in a Valve.

You can, of course, instantiate the spring context in the Valve constructor, and use context.autowireBean(this) there, but this will be a separate spring context, not one from any of the contexts available.

Technically, you have access to the contexts from the Valve, but afaik it is from the request, so you can obtain the ApplicationContext for each servlet context, and from there - get a reference to a bean, but that sounds odd.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜