Results 1 to 6 of 6

Thread: Sprin g MVC and AOP

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Posts
    9

    Default 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. #2
    Join Date
    Feb 2007
    Location
    Milan - Italy
    Posts
    19

    Default AOP e Spring MVC

    Maybe here you can find something useful:

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

  3. #3
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

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

  4. #4
    Join Date
    Aug 2006
    Posts
    9

    Default

    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

  5. #5
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  6. #6
    Join Date
    Aug 2006
    Location
    Brooklyn
    Posts
    556

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •