开发者

Custom spring interceptor

I want to convert so开发者_运维百科me of our internal API into a spring bean spring interceptor that we can use in other projects. This API needs some instantiation and other logic which I want to encapsulate in this bean so that we can just put the bean into our app context with necessary propoerties alone, and this will then apply the logic.

I remember having read an article on this somewhere in the past - but cant find it now. Any pointers to something similar will be helpful

EDIT: Sorry, I meant a spring interceptor, not a bean - my bad - please see my edit. I want to apply this interceptor to another bean dealing in XML messages.

EDIT 2: ANSWER FOUND found it!

I found the answer to this - we were looking to insert the interceptor at the point where we were calling our webservice. So I looked at the interceptor package in spring-ws and found this end point interceptor interface. We will now implement this interceptor and put our processing logic in the appropriate handle*() method.

http://static.springsource.org/spring-ws/sites/1.5/apidocs/org/springframework/ws/server/EndpointInterceptor.html


As with everything in spring, there are a million ways to implement AOP. Check out the spring doco on AOP, the section on declaring aspects in xml may be the most convenient in your situation. You can configure an aspect

<aop:aspect id="myAspect" ref="existingBean">
    <aop:before pointcut="execution(* com.package.to.intercept.*(..))" method="existingMethod"/>
</aop:aspect>

Or you could create new classes that use the AspectJ annotations and use those aspects to farm off to your actual work to your existing beans.


Found it!

See this link - http://static.springsource.org/spring-flex/docs/1.0.x/reference/html/ch02s09.html

This gives the interface that you need to implement and the XML definition.

Found a more suitable answer - see the edit in main question.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜