Announcement Announcement Module
Collapse
No announcement yet.
Sprin g MVC and AOP Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sprin g MVC and AOP

    I'm using Spring MVC framework with jdk 1.4 ( no annotations yet ) and have a requirement to add some method access security, logging and exception handlers...at first sight seems that AOP would fit perfectly.


    Please note that I'm using mostly multi action controllers.

    I tried to configure a simple around/before interceptors for logging,but none of them works.

    Would you please point me in the right direction? Any suggestions would be greatly appreciated.

    Thanks,
    Vali

  • #2
    AOP e Spring MVC

    Maybe here you can find something useful:

    http://www.internna.blogspot.com/

    Comment


    • #3
      Have you looked at Acegi Security System for Spring?
      http://www.acegisecurity.org/

      Comment


      • #4
        Thanks for the reply, yes I'm considering Acegi framework for security. At this moment I'm more interested to implement some interceptors for logging and exception handling. I've spent some time looking around and it seems that Spring AOP won't work with the multiaction controllers. As I mentioned I use jdk 1.4, so annotations are available to me.

        I'm gonna look and see if I can weave AspectJ aspects at runtime. If you guys have any samples or hints that I can use please let me know.

        Regards,
        Valy

        Comment


        • #5
          Controllers only have on public method handleRequest. Spring AOP can only intercept method calls made INTO the bean. The only methodcall from outside the controller is handleRequest all other method calls are internal calls and cannot be intercepted by Spring.

          If you want this you will need to use a fullblown AOP solution.

          Comment


          • #6
            You should be able to use Spring 1.2 AOP. You create a MethodInterceptor and hook it with a ProxyFactoryBean. Here is some sample configuration:

            Code:
            <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
                <property name="mappings">
                    <props>
                        <prop key="/**">myController</prop>
                    </props>
                </property>
            </bean>
            
            <bean id="myController" class="org.springframework.aop.framework.ProxyFactoryBean">
                <property name="proxyInterfaces">
                    <value>org.springframework.web.servlet.mvc.Controller</value>
                </property>
                <property name="interceptorNames">
                    <list>
                        <value>myInterceptor</value>
                    </list>
                </property>
                <property name="target">
                    <bean class="com.mycompany.MyMultiActionController"/>
                </property>
            </bean>
            
            <bean id="myInterceptor" class="com.mycompany.MyInterceptor"/>
            And the interceptor class:

            Code:
            public class MyInterceptor implements org.aopalliance.intercept.MethodInterceptor {
            
                public Object invoke(MethodInvocation invocation) throws Throwable {
            
            		// perform security check
            
                    return invocation.proceed();
                }
            }
            Rossen

            Comment

            Working...
            X