SlideShare a Scribd company logo
1 of 46
Download to read offline
Aspect Oriented
                                                                      Programming and
                                                                       MVC with Spring
                                                                             Framework

http://www.packtpub.com/aspect-oriented-programming-with-spring-2-5/book




                                          Massimiliano Dessì - desmax74@yahoo.it
                                                      Lugano - 29/01/2009
Author
Java Architect   2008




Co-founder

JugSardegna Onlus       2003




Founder:

SpringFramework Italian User Group                     2006




Jetspeed Italian User Group            2003




Groovy Italian User Group             2007




                           Massimiliano Dessì - desmax74@yahoo.it
                                       Lugano - 29/01/2009
Spring Knowledge
Spring User
since July 2004
(Spring 1.1)

First article in
Italy,
september 2004
on JugSardegna.




                   Massimiliano Dessì - desmax74@yahoo.it
                               Lugano - 29/01/2009
Spring origin

2003: Spring is a layered J2EE application framework based on code
                             published in
  “Expert One-on-One J2EE Design and Development” by Rod
                                Johnson.”




                      Massimiliano Dessì - desmax74@yahoo.it
                                  Lugano - 29/01/2009
Spring core
The core of the Spring Framework is based on the principle of
Inversion of Control (IoC).
Applications that follow the IoC principle use configuration that
describes the dependencies between its components.
It is then up to the IoC framework to satisfy the configured
dependencies.


Ioc, also known as the Hollywood Principle - quot;Don't call us, we'll call
youquot;
http://martinfowler.com/bliki/InversionOfControl.html


                                     Massimiliano Dessì - desmax74@yahoo.it
                                                 Lugano - 29/01/2009
Spring overview




            Massimiliano Dessì - desmax74@yahoo.it
                        Lugano - 29/01/2009
Spring XML configuration
 <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?>
 <beans xmlns=quot;http://www.springframework.org/schema/beansquot;
 xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot; xmlns:p=quot;http://www.springframework.org/schema/pquot;
 xmlns:aop=quot;http://www.springframework.org/schema/aopquot; xmlns:tx=quot;http://www.springframework.org/schema/txquot;
 xmlns:context=quot;http://www.springframework.org/schema/contextquot; xsi:schemaLocation=quot;http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsdquot;>

 <context:component-scan base-package=quot;it.freshfruitsquot; />
 <context:property-placeholder location=quot;WEB-INF/conf/spring/config.propertiesquot; />

 <bean id=quot;viewResolverquot; class=quot;org.springframework.web.servlet.view.InternalResourceViewResolverquot;
        p:viewClass=quot;org.springframework.web.servlet.view.JstlViewquot; p:prefix=quot;WEB-INF/jsp/quot; p:suffix=quot;.jspquot;/>

 <bean name=quot;dataSourcequot; class=quot;org.springframework.jndi.JndiObjectFactoryBeanquot; p:jndiName=quot;java:comp/env/jdbc/sffsquot;/>

 <bean id=quot;sqlMapClientquot; class=quot;org.springframework.orm.ibatis.SqlMapClientFactoryBeanquot; p:dataSource-ref=quot;dataSourcequot; p
        :configLocation=quot;WEB-INF/conf/ibatis/sffs-sqlMapConfig.xmlquot;/>

 <bean id=quot;transactionManagerquot; class=quot;org.springframework.jdbc.datasource.DataSourceTransactionManagerquot; p:dataSource-ref=quot;dataSourcequot;/>

 <tx:advice id=quot;txAdvicequot; transaction-manager=quot;transactionManagerquot;>
        <tx:attributes>
                <tx:method name=quot;save*quot; propagation=quot;REQUIREDquot; rollback-for=quot;Exceptionquot;/>
                <tx:method name=quot;insertOrderquot; propagation=quot;REQUIREDquot; rollback-for=quot;OrderItemsExceptionquot;/>
                <tx:method name=quot;insert*quot; propagation=quot;REQUIREDquot; rollback-for=quot;DataAccessExceptionquot;/>
                <tx:method name=quot;update*quot; propagation=quot;REQUIREDquot; rollback-for=quot;DataAccessExceptionquot;/>
                <tx:method name=quot;delete*quot; propagation=quot;REQUIREDquot; rollback-for=quot;DataAccessExceptionquot;/>
                <tx:method name=quot;disable*quot; propagation=quot;REQUIREDquot; rollback-for=quot;DataAccessExceptionquot;/>
                <tx:method name=quot;*quot; read-only=quot;truequot;/>
        </tx:attributes>
 </tx:advice>

 <aop:config>
        <aop:pointcut id=quot;repoOperationsquot; expression=quot;execution(* it.freshfruits.application.repository.*.*(..))quot; />
        <aop:advisor advice-ref=quot;txAdvicequot; pointcut-ref=quot;repoOperationsquot;/>
 </aop:config>

 </beans>




                                                Massimiliano Dessì - desmax74@yahoo.it
                                                            Lugano - 29/01/2009
AOP


The Aspect Oriented Programming supports the Object Oriented
 Programming in the implementation phase, where it presents
                            weak spots.
The AOP is complementary to OOP in the implementation phase.
                The AOP must be used with
                              wisdom.




                   Massimiliano Dessì - desmax74@yahoo.it
                               Lugano - 29/01/2009
OOP limits

Code scattering, when a feature is implemented in different
modules.
Two types:
- Blocks of duplicated code (for instance identical implementation of
an interface in different classes)
- Complementary blocks of code of the same feature, located in different
modules.
 (for instance in an ACL, a module executes the authentication and
another one the authorization)



                         Massimiliano Dessì - desmax74@yahoo.it
                                     Lugano - 29/01/2009
OOP limits
Code tangling: a module has too many tasks at the same time.
public ModelAndView list(HttpServletRequest req, HttpServletResponse res)
    throws Exception {

    log(req);                                                  //logging

    if(req.isUserInRole(quot;adminquot;)){                             // authorization

        List users ;
        try {                                        //exception handling
    String username = req.getRemoteUser();
    users =cache.get(Integer.valueOf(conf.getValue(quot;numberOfUsersquot;)),
            username);                               //cache with authorization
    } catch (Exception e) {
        users = usersManager.getUsers();
    }

       return new ModelAndView(quot;usersTemplatequot;, quot;usersquot;, users);

    }else{
      return new ModelAndView(quot;notAllowedquot;);
    }
}


                           Massimiliano Dessì - desmax74@yahoo.it
                                       Lugano - 29/01/2009
Consequences

-Difficult evolution
-Poor quality
-Code not reusable
-Traceability
-Low productivity

Moreover, it's written in an Object Oriented language:
the implementation, not the language, is the problem !


                       Massimiliano Dessì - desmax74@yahoo.it
                                   Lugano - 29/01/2009
The source of the problem

The classes have to implement transversal features.




The problem now is not a class that must have only one
task/aim/responsibility/feature, the problem now is how that task
is called to be used.
                       Massimiliano Dessì - desmax74@yahoo.it
                                   Lugano - 29/01/2009
AOP Solution

The AOP provides the constructs and tools to centralize
these features that cross the application transversal
(crosscutting concerns).
Thus, the AOP permits to centralise the duplicated code
and apply it according to predetermined rules in the
requested places, during the execution flow.




                    Massimiliano Dessì - desmax74@yahoo.it
                                Lugano - 29/01/2009
AOP elements


Aspect: it corresponds to the class in the OOP; it contains the
transversal feature (crosscutting concern).
Joinpoint: point of execution of the code
(for instance a constructor's invocation, a method's execution
or the management of an Exception).
Advice: the action to be performed in the joinpoint.
Pointcut: it contains the expression that permits to locate the
joinpoint to which we want to apply the advice.


                      Massimiliano Dessì - desmax74@yahoo.it
                                  Lugano - 29/01/2009
AOP elements


Introduction: it allows to add interfaces and the
implementation in runtime to predetermined objects.
Target: class on which the aspect works with the advice
Weaving: This is the linking action between the aspect and the
objects to which advices must be applied.




                      Massimiliano Dessì - desmax74@yahoo.it
                                  Lugano - 29/01/2009
AOP diagram
          How the AOP works




              Massimiliano Dessì - desmax74@yahoo.it
                          Lugano - 29/01/2009
Spring AOP


To allow a simplified use of AOP, Spring uses the execution of
the methods as joinpoint.
This means that we can act before, after, around a method, at
the raise of an exception, whatever the result may be (finally).
We use normal Java classes with annotations or XML.
Who works in the shadow to allow this simplicity?
            java.lang.reflect.Proxy or CGLIB




                      Massimiliano Dessì - desmax74@yahoo.it
                                  Lugano - 29/01/2009
Spring AOP: take it easy
We only have to decide:

-what to centralise ?
-when does it have to come into
 action ?

What I can obtain:

-support to the Domain Driven Design
-less code
-code that is manageable and can be
  maintained
-less excuses to use really the OOP,
 and not to move data containers...

                     Massimiliano Dessì - desmax74@yahoo.it
                                 Lugano - 29/01/2009
Spring AOP - Concurrence

                                                             First part of the class:
@Aspect() @Order(0)
public class ConcurrentAspect {
                                                             - create some locks for
 private final ReadWriteLock lock =
                                                               reading and writing
   new ReentrantReadWriteLock();
 private final Lock rLock = lock.readLock();
 private final Lock wLock = lock.writeLock();
                                                             - put @Aspect on the class
 @Pointcut(quot;execution (* isAvailable(..))quot;)
 private void isAvailable() {}
                                                             - define with the annotation
                                                               @Pointcut the
 @Pointcut(quot;execution (* retainItem(..))quot;)
 private void retainItem() {}
                                                               expressions that indicate
                                                               when the         Aspect
 @Pointcut(quot;execution (* release(..))quot;)
                                                               has to operate.
 private void release() {}

 @Pointcut(quot;release() || retainItem()quot;)
 private void releaseOrRetain() {}




                          Massimiliano Dessì - desmax74@yahoo.it
                                      Lugano - 29/01/2009
Spring AOP - Concurrence
                                               Second part of the class:
    @Before(quot;isAvailable()quot;)
    public void setReadLock() {
                                               I define reusing the names of
        rLock.lock();
    }
                                               the methods on which I've
                                               annotated the @Pointcut the
    @After(quot;isAvailable()quot;)
    public void releaseReadLock() {
                                               logic to execute with locks
        rLock.unlock();
    }
                                               With the following annotations
    @Before(quot;releaseOrRetain()quot;)
                                               I declare when I want it to be
    public void setWriteLock() {
                                               executed
        wLock.lock();
    }
                                               @Before
    @After(quot;releaseOrRetain()quot;)
                                               @After
    public void releaseWriteLock() {
        wLock.unlock();
                                               @AfterReturning
    }
                                               @Around
}
                                               @AfterThrowing

                          Massimiliano Dessì - desmax74@yahoo.it
                                      Lugano - 29/01/2009
Spring AOP – Advice Type

                  Advices let us not only execute logic in the points
                  defined by pointcuts, but even to obtain informations
@Before
                  about execution (target class, method called,
                  argument passed, return value)
@After
                  With some kind of advices (around) even to have
                  control on the execution flow.
@AfterReturning
                  The calling class of course doesn't know anything
                  about what happens, it just sees a simple class ....
@Around

@AfterThrowing




                   Massimiliano Dessì - desmax74@yahoo.it
                               Lugano - 29/01/2009
Spring AOP – Pointcut

                  In the previous pointcuts we've seen how the expression
    execution
•


                  to define the application point was the execution of a
    within
•


                  method with a certain name.
    this
•


                  We have at our disposal other pointcut designators as
    target
•

                  well to have the maximum control.
    args
•



    @target
•



    @args
•



    @within
•



    @annotation
•



    bean
●




                       Massimiliano Dessì - desmax74@yahoo.it
                                   Lugano - 29/01/2009
Spring AOP – JMX

@ManagedResource(quot;freshfruitstore:type=TimeExecutionManagedAspectquot;)
@Aspect() @Order(2)
public class TimeExecutionManagedAspect {

                                                                   besides being able to act in
  @ManagedAttribute
  public long getAverageCallTime() {
                                                                   the execution flow, I can
    return (this.callCount > 0
     ? this.accumulatedCallTime / this.callCount : 0);
  }
                                                                   manage the Aspect with
  @ManagedOperation
                                                                   JMX as well,exposing as
  public void resetCounters() {
     this.callCount = 0;
                                                                   attributes or operations, the
     this.accumulatedCallTime = 0;
  }

                                                                   normal methods of Aspect
  @ManagedAttribute
  public long getAverageCallTime() {
                                                                   which is always a Java
    return (this.callCount > 0 ?
     this.accumulatedCallTime / this.callCount : 0);
  }
                                                                   class
    ...




                              Massimiliano Dessì - desmax74@yahoo.it
                                          Lugano - 29/01/2009
Spring AOP – JMX
...

                                                                         Using JMX
@Around(quot;within(it.mypackage.service.*Impl)quot;)
public Object invoke(ProceedingJoinPoint joinPoint)
                                                                         I can change
    throws Throwable {

      if (this.isTimeExecutionEnabled) {
                                                                   the      behaviour of
         StopWatch sw = new StopWatch(joinPoint.toString());
         sw.start(quot;invokequot;);
                                                                   the      Aspect at runtime
         try {
             return joinPoint.proceed();
         } finally {
             sw.stop();
             synchronized (this) {
                this.accumulatedCallTime += sw.getTotalTimeMillis();
             }
                logger.info(sw.prettyPrint());
             }
         } else {
             return joinPoint.proceed();
         }
       }
...




                                Massimiliano Dessì - desmax74@yahoo.it
                                            Lugano - 29/01/2009
Spring AOP – Introductions

An introduction allows to decorate an object
with interfaces and its implementation.
That allows us both to avoid the duplication of
an implementation, and to simulate the
multiple inheritance that Java doesn't have.


@Aspect
public class ParallelepipedIntroduction {

    @DeclareParents(value = quot;org.springaop.chapter.four.introduction.Boxquot;,
        defaultImpl = Titanium.class)
    public Matter matter;

    @DeclareParents(value = quot;org.springaop.chapter.four.introduction.Boxquot;,
        defaultImpl = Cube.class)
    public GeometricForm geometricForm;
}


                             Massimiliano Dessì - desmax74@yahoo.it
                                         Lugano - 29/01/2009
SpringAOP - @Aspect

The annotations we've seen so far included pointcuts syntax are provided
by AspectJ.

import org.aspectj.lang.annotation.*

but they're completely inside Spring's “context” and on Spring's beans.
Now let's look at what we can use of Sring (IoC) outside Spring's “context”
through AspectJ.
We'll have to accept some compromise...




                        Massimiliano Dessì - desmax74@yahoo.it
                                    Lugano - 29/01/2009
DDD

                                                         Domain-Driven Design is a way of
                         Aggregates
  Entities
                                                         thinking applications.
               Modules                                   Suggesting to focus the attention
                                      Factories

                                                         on the problem domain, inviting to
Services
                                                         think by ojects and not with
                               Repositories
             Value Objects                               procedural style design.

                             Infrastructure Layer
Application Layer



                                 UI Layer
      Domain Layer



                                Massimiliano Dessì - desmax74@yahoo.it
                                            Lugano - 29/01/2009
DDD

                                                                               In the entities it is
public interface Customer extends NamedEntity {
                                                                               concentrated the
    public Address getAddress();
                                                                               business logic, not in the
    public ContactInformation getContact();

                                                                               services that execute
    public void modifyContactInformation(ContactInformation contact);

    public void modifyAddress(Address address);
                                                                               “procedures”...
    public Boolean saveCustomer();

                                                                               In this way our objects
    public Boolean createOrder();

    public Boolean saveOrder();
                                                                               have data and behaviours
    public Order getOrder();

    public List<Order> getOrders();
}




                                      Massimiliano Dessì - desmax74@yahoo.it
                                                  Lugano - 29/01/2009
SpringAOP +DDD +AspectJ

@Configurable(dependencyCheck = true, autowire=Autowire.BY_TYPE)
public class CustomerImpl implements Customer, Serializable {

      @Autowired
      public void setCustomerRepository(@Qualifier(quot;customerRepositoryquot;) CustomerRepository customerRepo) {
           this.customerRepository = customerRepository;
      }

      @Autowired
      public void setOrderRepository(@Qualifier(quot;orderRepositoryquot;) OrderRepository orderRepo) {
           this.orderRepository = orderRepo;
      }


      public Boolean createOrder() {
           Boolean result = false;
           if (order == null) {
                order = new OrderImpl.Builder(Constants.ID_NEW, new Date(), id
                          .toString()).build();
                result = true;
           }
           return result;
      }

      public Boolean saveCustomer() {
           return customerRepository.saveCustomer(this);
      }

...



                                     Massimiliano Dessì - desmax74@yahoo.it
                                                 Lugano - 29/01/2009
SpringAOP +AspectJ

With @Configurable we have declared that some dependencies will e
injected to the class even if it isn't a Spring bean.
Spring applicationContext knows the class just as a bean prototype.
In order to have this feature we need to pass to the JVM the Spring's jar to
use for the Load Time Weaving:
-javaagent:<path>spring-agent.jar

or to configure tomcat in this way to do it in our stead :
<Loader
loaderClass=quot;org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoaderquot;
     useSystemClassLoaderAsParent=quot;falsequot;/>




                                Massimiliano Dessì - desmax74@yahoo.it
                                            Lugano - 29/01/2009
Spring AOP +AspectJ Weaver

Using AspectJ Weaver implies a different approach compared with
SpringAOP's simplicity see so far.
Annotating classes as @Aspect and making create them by Spring, means
staying anyway into the IoC Container, like defining pointcuts on methods
executions by beans of Spring.
With LTW we're telling to Spring to work outside its “context, to inject
dependencies on objects not created by the IoC container.
In order to use LTW we define in a file for AspectJ the classes on which it
has to operate and which Aspects it has to create, Aspects that are not
beans created by Spring...


                          Massimiliano Dessì - desmax74@yahoo.it
                                      Lugano - 29/01/2009
LTW - aop.xml

100% AspectJ

<!DOCTYPE aspectj PUBLIC quot;-//AspectJ//DTD//ENquot;
quot;http://www.eclipse.org/aspectj/dtd/aspectj.dtdquot;>
<aspectj>
<weaver options=quot;-showWeaveInfo
-XmessageHandlerClass:org.springframework.aop.aspectj.AspectJWeaverMessageHandlerquot;>
     <!-- only weave classes in our application-specific packages -->
     <include within=quot;it.freshfruits.domain.entity.*quot;/>
     <include within=quot;it.freshfruits.domain.factory.*quot;/>
     <include within=quot;it.freshfruits.domain.service.*quot;/>
     <include within=quot;it.freshfruits.domain.vo.*quot;/>
     <include within=quot;it.freshfruits.application.repository.*quot;/>
     <exclude within=quot;it.freshfruits.aspect.*quot;/>
</weaver>
<aspects>
        <aspect name=quot;it.freshfruits.aspect.ConcurrentAspectquot; />
        <aspect name=quot;it.freshfruits.aspect.LogManagedAspectquot; />
        <aspect name=quot;it.freshfruits.aspect.TimeExecutionManagedAspectquot; />
</aspects>
</aspectj>




                                  Massimiliano Dessì - desmax74@yahoo.it
                                              Lugano - 29/01/2009
Spring AOP +AspectJ Weaver

Once we have the dependencies in an entity of the domain ( with LTW or or
constructor arguments), we see the result on the User Interface.




                        Massimiliano Dessì - desmax74@yahoo.it
                                    Lugano - 29/01/2009
DDD UI
@Controller(quot;customerControllerquot;)
public class CustomerController {

      @RequestMapping(quot;/customer.create.pagequot;)
      public ModelAndView create(HttpServletRequest req) {
        return new ModelAndView(quot;customer/createquot;, quot;resultquot;, UiUtils.getCustomer(req).createOrder());
      }

      @RequestMapping(quot;/customer.order.pagequot;)
      public ModelAndView order(HttpServletRequest req) {
        return new ModelAndView(quot;customer/orderquot;, quot;orderquot;, UiUtils.getOrder(req));
      }

      @RequestMapping(quot;/customer.items.pagequot;)
      public ModelAndView items(HttpServletRequest req) {
        return new ModelAndView(quot;customer/itemsquot;, quot;itemsquot;, UiUtils.getOrder(req).getOrderItems());
      }
...
}

The controllers will be completely stateless and without dependencies, with a
simple call on the entity.


                                       Massimiliano Dessì - desmax74@yahoo.it
                                                   Lugano - 29/01/2009
DDD UI
Handler Interceptor which puts int the HttpServletRequest the entity
customer used by the Customer Controller

public class CustomerInterceptor extends HandlerInterceptorAdapter {

  @Override
  public boolean preHandle(HttpServletRequest req, HttpServletResponse res, Object handler) throws
Exception {
    req.setAttribute(Constants.CUSTOMER, customerFactory.getCurrentCustomer());
    return true;
  }

    @Autowired
    private CustomerFactory customerFactory;
}




                                   Massimiliano Dessì - desmax74@yahoo.it
                                               Lugano - 29/01/2009
Benefits




   OOP + AOP + DDD
           =
      clean code
     elegant code




             Massimiliano Dessì - desmax74@yahoo.it
                         Lugano - 29/01/2009
Spring MVC
                                                                                 Handler Mapping
                                                                 2



                                                             3
Request     1
                                                                                   Controller
                Dispatcher Servlet                 ModelAndView
                                                                             4
 Response



                                                                         5
                                                                                 ViewResolver


                                                                     6

                                                                                    View



                              Massimiliano Dessì - desmax74@yahoo.it
                                          Lugano - 29/01/2009
Form Controller
@Controller(quot;fruitControllerquot;) @RequestMapping(quot;/fruit.edit.adminquot;) @SessionAttributes(quot;fruitquot;)
public class FruitController {

    @RequestMapping(method = RequestMethod.POST)
    public String processSubmit(@ModelAttribute(quot;fruitquot;) FruitMap fruit, BindingResult result,
               SessionStatus status) {

        validator.validate(fruit, result);
        if (result.hasErrors()) {
            return quot;userFormquot;;
        } else {
            fruit.save();
            status.setComplete();
            return quot;redirect:role.list.adminquot;;
        }
    }

    @InitBinder()
    public void initBinder(WebDataBinder binder) throws Exception {
        binder.registerCustomEditor(String.class, new StringTrimmerEditor(false));
    }

    @RequestMapping(method = RequestMethod.GET)
    public String setupForm(@RequestParam(required = false, value = quot;idquot;) Integer id, ModelMap model) {
        model.addAttribute(Constants.FRUIT, id == null ? new FruitMap() : fruitRepository.getFruitType(id));
        return quot;role/formquot;;
    }

    @Autowired @Qualifier(quot;fruitRepositoryquot;)
    private FruitTypeRepository fruitRepository;
    @Autowired @Qualifier(quot;fruitValidatorquot;)
    private FruitValidator validator;
}


                                    Massimiliano Dessì - desmax74@yahoo.it
                                                Lugano - 29/01/2009
MultiAction Controller
@Controller(quot;customerControllerquot;)
public class CustomerController {

    @RequestMapping(quot;/customer.create.pagequot;)
    public ModelAndView create(HttpServletRequest req) {
        return new ModelAndView(quot;customer/createquot;, quot;resultquot;, UiUtils.getCustomer(req).createOrder());
    }

    @RequestMapping(quot;/customer.save.pagequot;)
    public ModelAndView save(HttpServletRequest req) {
        return new ModelAndView(quot;customer/savequot;, quot;resultquot;, UiUtils.getCustomer(req).saveOrder());
    }

    @RequestMapping(quot;/customer.show.pagequot;)
    public ModelAndView show(HttpServletRequest req) {
        return new ModelAndView(quot;customer/showquot;, quot;customerquot;, UiUtils.getCustomer(req));
    }

    @RequestMapping(quot;/customer.order.pagequot;)
    public ModelAndView order(HttpServletRequest req) {
        return new ModelAndView(quot;customer/orderquot;, quot;orderquot;, UiUtils.getOrder(req));
    }

    @RequestMapping(quot;/customer.items.pagequot;)
    public ModelAndView items(HttpServletRequest req) {
        return new ModelAndView(quot;customer/itemsquot;, quot;itemsquot;, UiUtils.getOrder(req).getOrderItems());
    }

    @RequestMapping(quot;/customer.remove.pagequot;)
    public ModelAndView remove(@RequestParam(quot;idquot;) String id, HttpServletRequest req) throws Exception {
        Order order = UiUtils.getOrder(req);
        return order.removeOrderItem(order.getId().toString(), id) ? new ModelAndView(quot;customer/itemsquot;,
           quot;itemsquot;, order.getOrderItems()) : new ModelAndView(quot;customer/removequot;, quot;resultquot;, false);
    }
}

                                    Massimiliano Dessì - desmax74@yahoo.it
                                                Lugano - 29/01/2009
Configuration

<beans xmlns=quot;http://www.springframework.org/schema/beansquot;
xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot; xmlns:p=quot;http://www.springframework.org/schema/pquot;
xmlns:context=quot;http://www.springframework.org/schema/contextquot;
xsi:schemaLocation=quot;http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsdquot;>

<context:component-scan base-package=quot;it.freshfruits.uiquot;/>

<bean name=quot;urlMappingquot; class=quot;org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMappingquot;>
     <property name=quot;interceptorsquot;>
           <list>
                <ref bean=quot;customerInterceptorquot;/>
            </list>
      </property>
</bean>

<bean name=quot;customerInterceptorquot; class=quot;it.freshfruits.ui.interceptor.CustomerInterceptorquot;/>

</beans>




                                   Massimiliano Dessì - desmax74@yahoo.it
                                               Lugano - 29/01/2009
Spring Security
<?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?>
<beans xmlns=quot;http://www.springframework.org/schema/beansquot; xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot;
xmlns:p=quot;http://www.springframework.org/schema/pquot; xmlns:sec=quot;http://www.springframework.org/schema/securityquot;
xsi:schemaLocation=quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.4.xsdquot;>

       <sec:http>
              <sec:intercept-url pattern=quot;/log*.jspquot; filters=quot;nonequot; />
              <sec:intercept-url pattern=quot;/*.pagequot; access=quot;ROLE_USERquot; />
              <sec:intercept-url pattern=quot;/*.adminquot; access=quot;ROLE_ADMINquot; />
              <sec:form-login login-page=quot;/login.jspquot; default-target-url=quot;/quot; login-processing-url=quot;/j_security_checkquot;
                     authentication-failure-url=quot;/loginError.jspquot; />
              <sec:logout logout-url=quot;/logout.jspquot; invalidate-session=quot;truequot; logout-success-url=quot;/login.jspquot; />
              <sec:remember-me />
              <sec:intercept-url pattern=quot;*.htmquot; access=quot;ROLE_USER,ROLE_ANONYMOUSquot; />
              <sec:intercept-url pattern=quot;*.pagequot; access=quot;ROLE_USER,ROLE_ADMINquot; />
              <sec:intercept-url pattern=quot;*.editquot; access=quot;ROLE_USER,ROLE_ADMINquot; />
              <sec:intercept-url pattern=quot;*.adminquot; access=quot;ROLE_ADMINquot; />
       </sec:http>

       <sec:authentication-provider user-service-ref=quot;sffsUserDetailservicequot;><sec:password-encoder hash=quot;shaquot; /></sec:authentication-provider>

       <bean id=quot;accessDecisionManagerquot; class=quot;org.springframework.security.vote.AffirmativeBasedquot;>
               <property name=quot;decisionVotersquot;>
                      <list>
                              <bean class=quot;org.springframework.security.vote.RoleVoterquot; />
                              <bean class=quot;org.springframework.security.vote.AuthenticatedVoterquot; />
                      </list>
               </property>
       </bean>

       <bean id=quot;sffsUserDetailservicequot; class=quot;it.freshfruits.security.AuthenticationJdbcDaoImplquot;
              p:rolePrefix=quot;ROLE_quot; p:dataSource-ref=quot;dataSourcequot;
              p:usersByUsernameQuery=quot;SELECT username, password, enabled FROM authentication WHERE username = ?quot;
              p:authoritiesByUsernameQuery=quot;SELECT username, authority FROM roles WHERE username = ?quot; />

       <sec:global-method-security access-decision-manager-ref=quot;accessDecisionManagerquot;>
               <sec:protect-pointcut expression=quot;execution(* it.freshfruits.domain.entity.*.*(..))quot;
                      access=quot;ROLE_USER,ROLE_ADMINquot; />
       </sec:global-method-security>
...

</beans>



                                                      Massimiliano Dessì - desmax74@yahoo.it
                                                                  Lugano - 29/01/2009
WEB.XML
...
<context-param>
     <param-name>webAppRootKey</param-name>
     <param-value>springFreshFruitsStore.root</param-value>
</context-param>
<context-param>
     <param-name>contextConfigLocation</param-name>
     <param-value>/WEB-INF/conf/spring/sffs-*.xml</param-value>
</context-param>
<listener>
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
     <filter-name>springSecurityFilterChain</filter-name>
     <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<servlet>
     <servlet-name>sffs</servlet-name>
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
     <load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping><servlet-name>sffs</servlet-name><url-pattern>*.page</url-pattern></servlet-mapping>
<servlet-mapping><servlet-name>sffs</servlet-name><url-pattern>*.edit</url-pattern></servlet-mapping>
<servlet-mapping><servlet-name>sffs</servlet-name><url-pattern>*.admin</url-pattern></servlet-mapping>
<servlet-mapping><servlet-name>sffs</servlet-name><url-pattern>*.htm</url-pattern></servlet-mapping>
...




                                    Massimiliano Dessì - desmax74@yahoo.it
                                                Lugano - 29/01/2009
Jsp paginated list
<%@ include file=quot;/WEB-INF/jsp/taglibs.jspquot;%>
<tag:pager href=quot;user.list.pagequot;/>
<div>
    <div align=quot;centerquot;><span><spring:message code=quot;ui.usersquot;/></span></div>
    <c:if test=quot;${msg ne ''}quot;>${msg}</c:if>
    <table class=quot;listquot;>
        <thead><tr><th align=quot;leftquot;><spring:message code=quot;ui.user.usernamequot;/></th></tr></thead>
        <tbody>
        <c:forEach var=quot;userquot; items=quot;${users}quot; varStatus=quot;statusquot;>
             <c:choose>
             <c:when test=quot;${status.count % 2 == 0}quot;>
             <tr class=quot;table-row-dispariquot;></c:when>
             <c:otherwise>
             <tr class=quot;table-row-pariquot;></c:otherwise>
             </c:choose>
                 <td align=quot;leftquot;>${user.username}</td>
                 <td align=quot;centerquot;>
                   <a href=quot;user.roles.page?sid=${user.id}quot;><img border=quot;0quot; title=quot;<spring:message code=quot;ui.action.viewquot;/>quot;
                   alt=quot;<spring:message code=quot;ui.action.viewquot;/>quot; src=quot;img/view.pngquot;/></a>
                 </td>
                 <td align=quot;centerquot;>
                   <a href=quot;user.detail.page?sid=${user.id}quot;><img border=quot;0quot; title=quot;<spring:message code=quot;ui.action.editquot;/>quot;
                   alt=quot;<spring:message code=quot;ui.action.editquot;/>quot; src=quot;img/edit.pngquot;/></a></td>
             </tr>
        </c:forEach>
        </tbody>
    </table>
</div>
<br/>
<tag:pager href=quot;user.list.pagequot;/>
<div align=quot;centerquot;>
<input type=quot;imagequot; src=quot;img/add.pngquot; title=quot;<spring:message code=quot;ui.action.user.newquot;/>quot; alt=quot;<spring:message
code=quot;ui.action.user.newquot;/>quot; onclick=quot;location.href = 'user.edit.page'quot; value=quot;<spring:message code=quot;ui.action.user.newquot;/>quot;/>
</div>




                                           Massimiliano Dessì - desmax74@yahoo.it
                                                       Lugano - 29/01/2009
Spring AOP Book


                                                                       More information
                                                                        in February on :


                                                                           http://www.packtpub.com



                                                                      Thanks to Stefano Sanna for their support
                                                                                     in the
                                                                              completion of the book.




http://www.packtpub.com/aspect-oriented-programming-with-spring-2-5/book



                                         Massimiliano Dessì - desmax74@yahoo.it
                                                     Lugano - 29/01/2009
Q&A




  Massimiliano Dessì - desmax74@yahoo.it
              Lugano - 29/01/2009
Thanks for your
         attention !
          Massimiliano Dessì
          desmax74 at yahoo.it
                     http://jroller.com/desmax
              http://www.linkedin.com/in/desmax74
     http://wiki.java.net/bin/view/People/MassimilianoDessi
http://www.jugsardegna.org/vqwiki/jsp/Wiki?MassimilianoDessi



              Spring Framework Italian User Group
    http://it.groups.yahoo.com/group/SpringFramework-it




        Massimiliano Dessì - desmax74@yahoo.it
                    Lugano - 29/01/2009

More Related Content

Similar to Aspect Oriented Programming and MVC with Spring Framework

SiriusCon2016 - Modelling Spacecraft On-board Software with Sirius
SiriusCon2016 - Modelling Spacecraft On-board Software with SiriusSiriusCon2016 - Modelling Spacecraft On-board Software with Sirius
SiriusCon2016 - Modelling Spacecraft On-board Software with Sirius
Obeo
 
Aspect Oriented Software Development
Aspect Oriented Software DevelopmentAspect Oriented Software Development
Aspect Oriented Software Development
Jignesh Patel
 
Mobile First with Angular.JS - Владимир Цветков, Obecto
Mobile First with Angular.JS - Владимир Цветков, ObectoMobile First with Angular.JS - Владимир Цветков, Obecto
Mobile First with Angular.JS - Владимир Цветков, Obecto
beITconference
 
2014_report
2014_report2014_report
2014_report
K SEZER
 
Model2Roo - ACME
Model2Roo - ACMEModel2Roo - ACME
Model2Roo - ACME
jccastrejon
 

Similar to Aspect Oriented Programming and MVC with Spring Framework (20)

Spring aop
Spring aopSpring aop
Spring aop
 
A report on mvc using the information
A report on mvc using the informationA report on mvc using the information
A report on mvc using the information
 
SiriusCon2016 - Modelling Spacecraft On-board Software with Sirius
SiriusCon2016 - Modelling Spacecraft On-board Software with SiriusSiriusCon2016 - Modelling Spacecraft On-board Software with Sirius
SiriusCon2016 - Modelling Spacecraft On-board Software with Sirius
 
Aspect Oriented Software Development
Aspect Oriented Software DevelopmentAspect Oriented Software Development
Aspect Oriented Software Development
 
Performance analysis of synchronisation problem
Performance analysis of synchronisation problemPerformance analysis of synchronisation problem
Performance analysis of synchronisation problem
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Mobile First with Angular.JS - Владимир Цветков, Obecto
Mobile First with Angular.JS - Владимир Цветков, ObectoMobile First with Angular.JS - Владимир Цветков, Obecto
Mobile First with Angular.JS - Владимир Цветков, Obecto
 
MDD and modeling tools research
MDD and modeling tools researchMDD and modeling tools research
MDD and modeling tools research
 
Angularjs2 presentation
Angularjs2 presentationAngularjs2 presentation
Angularjs2 presentation
 
MODEL DRIVEN ARCHITECTURE, CONTROL SYSTEMS AND ECLIPSE
MODEL DRIVEN ARCHITECTURE, CONTROL SYSTEMS AND ECLIPSEMODEL DRIVEN ARCHITECTURE, CONTROL SYSTEMS AND ECLIPSE
MODEL DRIVEN ARCHITECTURE, CONTROL SYSTEMS AND ECLIPSE
 
Onion Architecture with S#arp
Onion Architecture with S#arpOnion Architecture with S#arp
Onion Architecture with S#arp
 
Architectural Design Pattern: Android
Architectural Design Pattern: AndroidArchitectural Design Pattern: Android
Architectural Design Pattern: Android
 
2014_report
2014_report2014_report
2014_report
 
micro-frontends-with-vuejs
micro-frontends-with-vuejsmicro-frontends-with-vuejs
micro-frontends-with-vuejs
 
How to migrate large project from Angular to React
How to migrate large project from Angular to ReactHow to migrate large project from Angular to React
How to migrate large project from Angular to React
 
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
 
Struts 1
Struts 1Struts 1
Struts 1
 
Model2Roo - ACME
Model2Roo - ACMEModel2Roo - ACME
Model2Roo - ACME
 
Agile Modeling using the Architecture Tools in VS 2010
Agile Modeling  using the Architecture Tools in VS 2010Agile Modeling  using the Architecture Tools in VS 2010
Agile Modeling using the Architecture Tools in VS 2010
 
Workshop About Software Engineering Skills 2019
Workshop About Software Engineering Skills 2019Workshop About Software Engineering Skills 2019
Workshop About Software Engineering Skills 2019
 

More from Massimiliano Dessì

More from Massimiliano Dessì (20)

Code One 2018 maven
Code One 2018   mavenCode One 2018   maven
Code One 2018 maven
 
When Old Meets New: Turning Maven into a High Scalable, Resource Efficient, C...
When Old Meets New: Turning Maven into a High Scalable, Resource Efficient, C...When Old Meets New: Turning Maven into a High Scalable, Resource Efficient, C...
When Old Meets New: Turning Maven into a High Scalable, Resource Efficient, C...
 
Hacking Maven Linux day 2017
Hacking Maven Linux day 2017Hacking Maven Linux day 2017
Hacking Maven Linux day 2017
 
Microservices in Go_Dessi_Massimiliano_Codemotion_2017_Rome
Microservices in Go_Dessi_Massimiliano_Codemotion_2017_Rome Microservices in Go_Dessi_Massimiliano_Codemotion_2017_Rome
Microservices in Go_Dessi_Massimiliano_Codemotion_2017_Rome
 
Dessi docker kubernetes paas cloud
Dessi docker kubernetes paas cloudDessi docker kubernetes paas cloud
Dessi docker kubernetes paas cloud
 
Docker dDessi november 2015
Docker dDessi november 2015Docker dDessi november 2015
Docker dDessi november 2015
 
Docker linuxday 2015
Docker linuxday 2015Docker linuxday 2015
Docker linuxday 2015
 
Openshift linuxday 2014
Openshift linuxday 2014Openshift linuxday 2014
Openshift linuxday 2014
 
Web Marketing Training 2014 Community Online
Web Marketing Training 2014 Community OnlineWeb Marketing Training 2014 Community Online
Web Marketing Training 2014 Community Online
 
Vert.X like Node.js but polyglot and reactive on JVM
Vert.X like Node.js but polyglot and reactive on JVMVert.X like Node.js but polyglot and reactive on JVM
Vert.X like Node.js but polyglot and reactive on JVM
 
Reactive applications Linux Day 2013
Reactive applications Linux Day 2013Reactive applications Linux Day 2013
Reactive applications Linux Day 2013
 
Scala Italy 2013 extended Scalatra vs Spring MVC
Scala Italy 2013 extended Scalatra vs Spring MVCScala Italy 2013 extended Scalatra vs Spring MVC
Scala Italy 2013 extended Scalatra vs Spring MVC
 
Codemotion 2013 scalatra_play_spray
Codemotion 2013 scalatra_play_sprayCodemotion 2013 scalatra_play_spray
Codemotion 2013 scalatra_play_spray
 
Why we cannot ignore functional programming
Why we cannot ignore functional programmingWhy we cannot ignore functional programming
Why we cannot ignore functional programming
 
Scala linux day 2012
Scala linux day 2012 Scala linux day 2012
Scala linux day 2012
 
Three languages in thirty minutes
Three languages in thirty minutesThree languages in thirty minutes
Three languages in thirty minutes
 
MongoDB dessi-codemotion
MongoDB dessi-codemotionMongoDB dessi-codemotion
MongoDB dessi-codemotion
 
MongoDB Webtech conference 2010
MongoDB Webtech conference 2010MongoDB Webtech conference 2010
MongoDB Webtech conference 2010
 
RESTEasy
RESTEasyRESTEasy
RESTEasy
 
Spring Roo Internals Javaday IV
Spring Roo Internals Javaday IVSpring Roo Internals Javaday IV
Spring Roo Internals Javaday IV
 

Recently uploaded

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Aspect Oriented Programming and MVC with Spring Framework

  • 1. Aspect Oriented Programming and MVC with Spring Framework http://www.packtpub.com/aspect-oriented-programming-with-spring-2-5/book Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 2. Author Java Architect 2008 Co-founder JugSardegna Onlus 2003 Founder: SpringFramework Italian User Group 2006 Jetspeed Italian User Group 2003 Groovy Italian User Group 2007 Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 3. Spring Knowledge Spring User since July 2004 (Spring 1.1) First article in Italy, september 2004 on JugSardegna. Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 4. Spring origin 2003: Spring is a layered J2EE application framework based on code published in “Expert One-on-One J2EE Design and Development” by Rod Johnson.” Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 5. Spring core The core of the Spring Framework is based on the principle of Inversion of Control (IoC). Applications that follow the IoC principle use configuration that describes the dependencies between its components. It is then up to the IoC framework to satisfy the configured dependencies. Ioc, also known as the Hollywood Principle - quot;Don't call us, we'll call youquot; http://martinfowler.com/bliki/InversionOfControl.html Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 6. Spring overview Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 7. Spring XML configuration <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?> <beans xmlns=quot;http://www.springframework.org/schema/beansquot; xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot; xmlns:p=quot;http://www.springframework.org/schema/pquot; xmlns:aop=quot;http://www.springframework.org/schema/aopquot; xmlns:tx=quot;http://www.springframework.org/schema/txquot; xmlns:context=quot;http://www.springframework.org/schema/contextquot; xsi:schemaLocation=quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsdquot;> <context:component-scan base-package=quot;it.freshfruitsquot; /> <context:property-placeholder location=quot;WEB-INF/conf/spring/config.propertiesquot; /> <bean id=quot;viewResolverquot; class=quot;org.springframework.web.servlet.view.InternalResourceViewResolverquot; p:viewClass=quot;org.springframework.web.servlet.view.JstlViewquot; p:prefix=quot;WEB-INF/jsp/quot; p:suffix=quot;.jspquot;/> <bean name=quot;dataSourcequot; class=quot;org.springframework.jndi.JndiObjectFactoryBeanquot; p:jndiName=quot;java:comp/env/jdbc/sffsquot;/> <bean id=quot;sqlMapClientquot; class=quot;org.springframework.orm.ibatis.SqlMapClientFactoryBeanquot; p:dataSource-ref=quot;dataSourcequot; p :configLocation=quot;WEB-INF/conf/ibatis/sffs-sqlMapConfig.xmlquot;/> <bean id=quot;transactionManagerquot; class=quot;org.springframework.jdbc.datasource.DataSourceTransactionManagerquot; p:dataSource-ref=quot;dataSourcequot;/> <tx:advice id=quot;txAdvicequot; transaction-manager=quot;transactionManagerquot;> <tx:attributes> <tx:method name=quot;save*quot; propagation=quot;REQUIREDquot; rollback-for=quot;Exceptionquot;/> <tx:method name=quot;insertOrderquot; propagation=quot;REQUIREDquot; rollback-for=quot;OrderItemsExceptionquot;/> <tx:method name=quot;insert*quot; propagation=quot;REQUIREDquot; rollback-for=quot;DataAccessExceptionquot;/> <tx:method name=quot;update*quot; propagation=quot;REQUIREDquot; rollback-for=quot;DataAccessExceptionquot;/> <tx:method name=quot;delete*quot; propagation=quot;REQUIREDquot; rollback-for=quot;DataAccessExceptionquot;/> <tx:method name=quot;disable*quot; propagation=quot;REQUIREDquot; rollback-for=quot;DataAccessExceptionquot;/> <tx:method name=quot;*quot; read-only=quot;truequot;/> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id=quot;repoOperationsquot; expression=quot;execution(* it.freshfruits.application.repository.*.*(..))quot; /> <aop:advisor advice-ref=quot;txAdvicequot; pointcut-ref=quot;repoOperationsquot;/> </aop:config> </beans> Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 8. AOP The Aspect Oriented Programming supports the Object Oriented Programming in the implementation phase, where it presents weak spots. The AOP is complementary to OOP in the implementation phase. The AOP must be used with wisdom. Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 9. OOP limits Code scattering, when a feature is implemented in different modules. Two types: - Blocks of duplicated code (for instance identical implementation of an interface in different classes) - Complementary blocks of code of the same feature, located in different modules. (for instance in an ACL, a module executes the authentication and another one the authorization) Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 10. OOP limits Code tangling: a module has too many tasks at the same time. public ModelAndView list(HttpServletRequest req, HttpServletResponse res) throws Exception { log(req); //logging if(req.isUserInRole(quot;adminquot;)){ // authorization List users ; try { //exception handling String username = req.getRemoteUser(); users =cache.get(Integer.valueOf(conf.getValue(quot;numberOfUsersquot;)), username); //cache with authorization } catch (Exception e) { users = usersManager.getUsers(); } return new ModelAndView(quot;usersTemplatequot;, quot;usersquot;, users); }else{ return new ModelAndView(quot;notAllowedquot;); } } Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 11. Consequences -Difficult evolution -Poor quality -Code not reusable -Traceability -Low productivity Moreover, it's written in an Object Oriented language: the implementation, not the language, is the problem ! Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 12. The source of the problem The classes have to implement transversal features. The problem now is not a class that must have only one task/aim/responsibility/feature, the problem now is how that task is called to be used. Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 13. AOP Solution The AOP provides the constructs and tools to centralize these features that cross the application transversal (crosscutting concerns). Thus, the AOP permits to centralise the duplicated code and apply it according to predetermined rules in the requested places, during the execution flow. Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 14. AOP elements Aspect: it corresponds to the class in the OOP; it contains the transversal feature (crosscutting concern). Joinpoint: point of execution of the code (for instance a constructor's invocation, a method's execution or the management of an Exception). Advice: the action to be performed in the joinpoint. Pointcut: it contains the expression that permits to locate the joinpoint to which we want to apply the advice. Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 15. AOP elements Introduction: it allows to add interfaces and the implementation in runtime to predetermined objects. Target: class on which the aspect works with the advice Weaving: This is the linking action between the aspect and the objects to which advices must be applied. Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 16. AOP diagram How the AOP works Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 17. Spring AOP To allow a simplified use of AOP, Spring uses the execution of the methods as joinpoint. This means that we can act before, after, around a method, at the raise of an exception, whatever the result may be (finally). We use normal Java classes with annotations or XML. Who works in the shadow to allow this simplicity? java.lang.reflect.Proxy or CGLIB Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 18. Spring AOP: take it easy We only have to decide: -what to centralise ? -when does it have to come into action ? What I can obtain: -support to the Domain Driven Design -less code -code that is manageable and can be maintained -less excuses to use really the OOP, and not to move data containers... Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 19. Spring AOP - Concurrence First part of the class: @Aspect() @Order(0) public class ConcurrentAspect { - create some locks for private final ReadWriteLock lock = reading and writing new ReentrantReadWriteLock(); private final Lock rLock = lock.readLock(); private final Lock wLock = lock.writeLock(); - put @Aspect on the class @Pointcut(quot;execution (* isAvailable(..))quot;) private void isAvailable() {} - define with the annotation @Pointcut the @Pointcut(quot;execution (* retainItem(..))quot;) private void retainItem() {} expressions that indicate when the Aspect @Pointcut(quot;execution (* release(..))quot;) has to operate. private void release() {} @Pointcut(quot;release() || retainItem()quot;) private void releaseOrRetain() {} Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 20. Spring AOP - Concurrence Second part of the class: @Before(quot;isAvailable()quot;) public void setReadLock() { I define reusing the names of rLock.lock(); } the methods on which I've annotated the @Pointcut the @After(quot;isAvailable()quot;) public void releaseReadLock() { logic to execute with locks rLock.unlock(); } With the following annotations @Before(quot;releaseOrRetain()quot;) I declare when I want it to be public void setWriteLock() { executed wLock.lock(); } @Before @After(quot;releaseOrRetain()quot;) @After public void releaseWriteLock() { wLock.unlock(); @AfterReturning } @Around } @AfterThrowing Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 21. Spring AOP – Advice Type Advices let us not only execute logic in the points defined by pointcuts, but even to obtain informations @Before about execution (target class, method called, argument passed, return value) @After With some kind of advices (around) even to have control on the execution flow. @AfterReturning The calling class of course doesn't know anything about what happens, it just sees a simple class .... @Around @AfterThrowing Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 22. Spring AOP – Pointcut In the previous pointcuts we've seen how the expression execution • to define the application point was the execution of a within • method with a certain name. this • We have at our disposal other pointcut designators as target • well to have the maximum control. args • @target • @args • @within • @annotation • bean ● Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 23. Spring AOP – JMX @ManagedResource(quot;freshfruitstore:type=TimeExecutionManagedAspectquot;) @Aspect() @Order(2) public class TimeExecutionManagedAspect { besides being able to act in @ManagedAttribute public long getAverageCallTime() { the execution flow, I can return (this.callCount > 0 ? this.accumulatedCallTime / this.callCount : 0); } manage the Aspect with @ManagedOperation JMX as well,exposing as public void resetCounters() { this.callCount = 0; attributes or operations, the this.accumulatedCallTime = 0; } normal methods of Aspect @ManagedAttribute public long getAverageCallTime() { which is always a Java return (this.callCount > 0 ? this.accumulatedCallTime / this.callCount : 0); } class ... Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 24. Spring AOP – JMX ... Using JMX @Around(quot;within(it.mypackage.service.*Impl)quot;) public Object invoke(ProceedingJoinPoint joinPoint) I can change throws Throwable { if (this.isTimeExecutionEnabled) { the behaviour of StopWatch sw = new StopWatch(joinPoint.toString()); sw.start(quot;invokequot;); the Aspect at runtime try { return joinPoint.proceed(); } finally { sw.stop(); synchronized (this) { this.accumulatedCallTime += sw.getTotalTimeMillis(); } logger.info(sw.prettyPrint()); } } else { return joinPoint.proceed(); } } ... Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 25. Spring AOP – Introductions An introduction allows to decorate an object with interfaces and its implementation. That allows us both to avoid the duplication of an implementation, and to simulate the multiple inheritance that Java doesn't have. @Aspect public class ParallelepipedIntroduction { @DeclareParents(value = quot;org.springaop.chapter.four.introduction.Boxquot;, defaultImpl = Titanium.class) public Matter matter; @DeclareParents(value = quot;org.springaop.chapter.four.introduction.Boxquot;, defaultImpl = Cube.class) public GeometricForm geometricForm; } Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 26. SpringAOP - @Aspect The annotations we've seen so far included pointcuts syntax are provided by AspectJ. import org.aspectj.lang.annotation.* but they're completely inside Spring's “context” and on Spring's beans. Now let's look at what we can use of Sring (IoC) outside Spring's “context” through AspectJ. We'll have to accept some compromise... Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 27. DDD Domain-Driven Design is a way of Aggregates Entities thinking applications. Modules Suggesting to focus the attention Factories on the problem domain, inviting to Services think by ojects and not with Repositories Value Objects procedural style design. Infrastructure Layer Application Layer UI Layer Domain Layer Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 28. DDD In the entities it is public interface Customer extends NamedEntity { concentrated the public Address getAddress(); business logic, not in the public ContactInformation getContact(); services that execute public void modifyContactInformation(ContactInformation contact); public void modifyAddress(Address address); “procedures”... public Boolean saveCustomer(); In this way our objects public Boolean createOrder(); public Boolean saveOrder(); have data and behaviours public Order getOrder(); public List<Order> getOrders(); } Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 29. SpringAOP +DDD +AspectJ @Configurable(dependencyCheck = true, autowire=Autowire.BY_TYPE) public class CustomerImpl implements Customer, Serializable { @Autowired public void setCustomerRepository(@Qualifier(quot;customerRepositoryquot;) CustomerRepository customerRepo) { this.customerRepository = customerRepository; } @Autowired public void setOrderRepository(@Qualifier(quot;orderRepositoryquot;) OrderRepository orderRepo) { this.orderRepository = orderRepo; } public Boolean createOrder() { Boolean result = false; if (order == null) { order = new OrderImpl.Builder(Constants.ID_NEW, new Date(), id .toString()).build(); result = true; } return result; } public Boolean saveCustomer() { return customerRepository.saveCustomer(this); } ... Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 30. SpringAOP +AspectJ With @Configurable we have declared that some dependencies will e injected to the class even if it isn't a Spring bean. Spring applicationContext knows the class just as a bean prototype. In order to have this feature we need to pass to the JVM the Spring's jar to use for the Load Time Weaving: -javaagent:<path>spring-agent.jar or to configure tomcat in this way to do it in our stead : <Loader loaderClass=quot;org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoaderquot; useSystemClassLoaderAsParent=quot;falsequot;/> Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 31. Spring AOP +AspectJ Weaver Using AspectJ Weaver implies a different approach compared with SpringAOP's simplicity see so far. Annotating classes as @Aspect and making create them by Spring, means staying anyway into the IoC Container, like defining pointcuts on methods executions by beans of Spring. With LTW we're telling to Spring to work outside its “context, to inject dependencies on objects not created by the IoC container. In order to use LTW we define in a file for AspectJ the classes on which it has to operate and which Aspects it has to create, Aspects that are not beans created by Spring... Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 32. LTW - aop.xml 100% AspectJ <!DOCTYPE aspectj PUBLIC quot;-//AspectJ//DTD//ENquot; quot;http://www.eclipse.org/aspectj/dtd/aspectj.dtdquot;> <aspectj> <weaver options=quot;-showWeaveInfo -XmessageHandlerClass:org.springframework.aop.aspectj.AspectJWeaverMessageHandlerquot;> <!-- only weave classes in our application-specific packages --> <include within=quot;it.freshfruits.domain.entity.*quot;/> <include within=quot;it.freshfruits.domain.factory.*quot;/> <include within=quot;it.freshfruits.domain.service.*quot;/> <include within=quot;it.freshfruits.domain.vo.*quot;/> <include within=quot;it.freshfruits.application.repository.*quot;/> <exclude within=quot;it.freshfruits.aspect.*quot;/> </weaver> <aspects> <aspect name=quot;it.freshfruits.aspect.ConcurrentAspectquot; /> <aspect name=quot;it.freshfruits.aspect.LogManagedAspectquot; /> <aspect name=quot;it.freshfruits.aspect.TimeExecutionManagedAspectquot; /> </aspects> </aspectj> Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 33. Spring AOP +AspectJ Weaver Once we have the dependencies in an entity of the domain ( with LTW or or constructor arguments), we see the result on the User Interface. Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 34. DDD UI @Controller(quot;customerControllerquot;) public class CustomerController { @RequestMapping(quot;/customer.create.pagequot;) public ModelAndView create(HttpServletRequest req) { return new ModelAndView(quot;customer/createquot;, quot;resultquot;, UiUtils.getCustomer(req).createOrder()); } @RequestMapping(quot;/customer.order.pagequot;) public ModelAndView order(HttpServletRequest req) { return new ModelAndView(quot;customer/orderquot;, quot;orderquot;, UiUtils.getOrder(req)); } @RequestMapping(quot;/customer.items.pagequot;) public ModelAndView items(HttpServletRequest req) { return new ModelAndView(quot;customer/itemsquot;, quot;itemsquot;, UiUtils.getOrder(req).getOrderItems()); } ... } The controllers will be completely stateless and without dependencies, with a simple call on the entity. Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 35. DDD UI Handler Interceptor which puts int the HttpServletRequest the entity customer used by the Customer Controller public class CustomerInterceptor extends HandlerInterceptorAdapter { @Override public boolean preHandle(HttpServletRequest req, HttpServletResponse res, Object handler) throws Exception { req.setAttribute(Constants.CUSTOMER, customerFactory.getCurrentCustomer()); return true; } @Autowired private CustomerFactory customerFactory; } Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 36. Benefits OOP + AOP + DDD = clean code elegant code Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 37. Spring MVC Handler Mapping 2 3 Request 1 Controller Dispatcher Servlet ModelAndView 4 Response 5 ViewResolver 6 View Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 38. Form Controller @Controller(quot;fruitControllerquot;) @RequestMapping(quot;/fruit.edit.adminquot;) @SessionAttributes(quot;fruitquot;) public class FruitController { @RequestMapping(method = RequestMethod.POST) public String processSubmit(@ModelAttribute(quot;fruitquot;) FruitMap fruit, BindingResult result, SessionStatus status) { validator.validate(fruit, result); if (result.hasErrors()) { return quot;userFormquot;; } else { fruit.save(); status.setComplete(); return quot;redirect:role.list.adminquot;; } } @InitBinder() public void initBinder(WebDataBinder binder) throws Exception { binder.registerCustomEditor(String.class, new StringTrimmerEditor(false)); } @RequestMapping(method = RequestMethod.GET) public String setupForm(@RequestParam(required = false, value = quot;idquot;) Integer id, ModelMap model) { model.addAttribute(Constants.FRUIT, id == null ? new FruitMap() : fruitRepository.getFruitType(id)); return quot;role/formquot;; } @Autowired @Qualifier(quot;fruitRepositoryquot;) private FruitTypeRepository fruitRepository; @Autowired @Qualifier(quot;fruitValidatorquot;) private FruitValidator validator; } Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 39. MultiAction Controller @Controller(quot;customerControllerquot;) public class CustomerController { @RequestMapping(quot;/customer.create.pagequot;) public ModelAndView create(HttpServletRequest req) { return new ModelAndView(quot;customer/createquot;, quot;resultquot;, UiUtils.getCustomer(req).createOrder()); } @RequestMapping(quot;/customer.save.pagequot;) public ModelAndView save(HttpServletRequest req) { return new ModelAndView(quot;customer/savequot;, quot;resultquot;, UiUtils.getCustomer(req).saveOrder()); } @RequestMapping(quot;/customer.show.pagequot;) public ModelAndView show(HttpServletRequest req) { return new ModelAndView(quot;customer/showquot;, quot;customerquot;, UiUtils.getCustomer(req)); } @RequestMapping(quot;/customer.order.pagequot;) public ModelAndView order(HttpServletRequest req) { return new ModelAndView(quot;customer/orderquot;, quot;orderquot;, UiUtils.getOrder(req)); } @RequestMapping(quot;/customer.items.pagequot;) public ModelAndView items(HttpServletRequest req) { return new ModelAndView(quot;customer/itemsquot;, quot;itemsquot;, UiUtils.getOrder(req).getOrderItems()); } @RequestMapping(quot;/customer.remove.pagequot;) public ModelAndView remove(@RequestParam(quot;idquot;) String id, HttpServletRequest req) throws Exception { Order order = UiUtils.getOrder(req); return order.removeOrderItem(order.getId().toString(), id) ? new ModelAndView(quot;customer/itemsquot;, quot;itemsquot;, order.getOrderItems()) : new ModelAndView(quot;customer/removequot;, quot;resultquot;, false); } } Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 40. Configuration <beans xmlns=quot;http://www.springframework.org/schema/beansquot; xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot; xmlns:p=quot;http://www.springframework.org/schema/pquot; xmlns:context=quot;http://www.springframework.org/schema/contextquot; xsi:schemaLocation=quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsdquot;> <context:component-scan base-package=quot;it.freshfruits.uiquot;/> <bean name=quot;urlMappingquot; class=quot;org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMappingquot;> <property name=quot;interceptorsquot;> <list> <ref bean=quot;customerInterceptorquot;/> </list> </property> </bean> <bean name=quot;customerInterceptorquot; class=quot;it.freshfruits.ui.interceptor.CustomerInterceptorquot;/> </beans> Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 41. Spring Security <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?> <beans xmlns=quot;http://www.springframework.org/schema/beansquot; xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot; xmlns:p=quot;http://www.springframework.org/schema/pquot; xmlns:sec=quot;http://www.springframework.org/schema/securityquot; xsi:schemaLocation=quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.4.xsdquot;> <sec:http> <sec:intercept-url pattern=quot;/log*.jspquot; filters=quot;nonequot; /> <sec:intercept-url pattern=quot;/*.pagequot; access=quot;ROLE_USERquot; /> <sec:intercept-url pattern=quot;/*.adminquot; access=quot;ROLE_ADMINquot; /> <sec:form-login login-page=quot;/login.jspquot; default-target-url=quot;/quot; login-processing-url=quot;/j_security_checkquot; authentication-failure-url=quot;/loginError.jspquot; /> <sec:logout logout-url=quot;/logout.jspquot; invalidate-session=quot;truequot; logout-success-url=quot;/login.jspquot; /> <sec:remember-me /> <sec:intercept-url pattern=quot;*.htmquot; access=quot;ROLE_USER,ROLE_ANONYMOUSquot; /> <sec:intercept-url pattern=quot;*.pagequot; access=quot;ROLE_USER,ROLE_ADMINquot; /> <sec:intercept-url pattern=quot;*.editquot; access=quot;ROLE_USER,ROLE_ADMINquot; /> <sec:intercept-url pattern=quot;*.adminquot; access=quot;ROLE_ADMINquot; /> </sec:http> <sec:authentication-provider user-service-ref=quot;sffsUserDetailservicequot;><sec:password-encoder hash=quot;shaquot; /></sec:authentication-provider> <bean id=quot;accessDecisionManagerquot; class=quot;org.springframework.security.vote.AffirmativeBasedquot;> <property name=quot;decisionVotersquot;> <list> <bean class=quot;org.springframework.security.vote.RoleVoterquot; /> <bean class=quot;org.springframework.security.vote.AuthenticatedVoterquot; /> </list> </property> </bean> <bean id=quot;sffsUserDetailservicequot; class=quot;it.freshfruits.security.AuthenticationJdbcDaoImplquot; p:rolePrefix=quot;ROLE_quot; p:dataSource-ref=quot;dataSourcequot; p:usersByUsernameQuery=quot;SELECT username, password, enabled FROM authentication WHERE username = ?quot; p:authoritiesByUsernameQuery=quot;SELECT username, authority FROM roles WHERE username = ?quot; /> <sec:global-method-security access-decision-manager-ref=quot;accessDecisionManagerquot;> <sec:protect-pointcut expression=quot;execution(* it.freshfruits.domain.entity.*.*(..))quot; access=quot;ROLE_USER,ROLE_ADMINquot; /> </sec:global-method-security> ... </beans> Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 42. WEB.XML ... <context-param> <param-name>webAppRootKey</param-name> <param-value>springFreshFruitsStore.root</param-value> </context-param> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/conf/spring/sffs-*.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <servlet> <servlet-name>sffs</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping><servlet-name>sffs</servlet-name><url-pattern>*.page</url-pattern></servlet-mapping> <servlet-mapping><servlet-name>sffs</servlet-name><url-pattern>*.edit</url-pattern></servlet-mapping> <servlet-mapping><servlet-name>sffs</servlet-name><url-pattern>*.admin</url-pattern></servlet-mapping> <servlet-mapping><servlet-name>sffs</servlet-name><url-pattern>*.htm</url-pattern></servlet-mapping> ... Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 43. Jsp paginated list <%@ include file=quot;/WEB-INF/jsp/taglibs.jspquot;%> <tag:pager href=quot;user.list.pagequot;/> <div> <div align=quot;centerquot;><span><spring:message code=quot;ui.usersquot;/></span></div> <c:if test=quot;${msg ne ''}quot;>${msg}</c:if> <table class=quot;listquot;> <thead><tr><th align=quot;leftquot;><spring:message code=quot;ui.user.usernamequot;/></th></tr></thead> <tbody> <c:forEach var=quot;userquot; items=quot;${users}quot; varStatus=quot;statusquot;> <c:choose> <c:when test=quot;${status.count % 2 == 0}quot;> <tr class=quot;table-row-dispariquot;></c:when> <c:otherwise> <tr class=quot;table-row-pariquot;></c:otherwise> </c:choose> <td align=quot;leftquot;>${user.username}</td> <td align=quot;centerquot;> <a href=quot;user.roles.page?sid=${user.id}quot;><img border=quot;0quot; title=quot;<spring:message code=quot;ui.action.viewquot;/>quot; alt=quot;<spring:message code=quot;ui.action.viewquot;/>quot; src=quot;img/view.pngquot;/></a> </td> <td align=quot;centerquot;> <a href=quot;user.detail.page?sid=${user.id}quot;><img border=quot;0quot; title=quot;<spring:message code=quot;ui.action.editquot;/>quot; alt=quot;<spring:message code=quot;ui.action.editquot;/>quot; src=quot;img/edit.pngquot;/></a></td> </tr> </c:forEach> </tbody> </table> </div> <br/> <tag:pager href=quot;user.list.pagequot;/> <div align=quot;centerquot;> <input type=quot;imagequot; src=quot;img/add.pngquot; title=quot;<spring:message code=quot;ui.action.user.newquot;/>quot; alt=quot;<spring:message code=quot;ui.action.user.newquot;/>quot; onclick=quot;location.href = 'user.edit.page'quot; value=quot;<spring:message code=quot;ui.action.user.newquot;/>quot;/> </div> Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 44. Spring AOP Book More information in February on : http://www.packtpub.com Thanks to Stefano Sanna for their support in the completion of the book. http://www.packtpub.com/aspect-oriented-programming-with-spring-2-5/book Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 45. Q&A Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009
  • 46. Thanks for your attention ! Massimiliano Dessì desmax74 at yahoo.it http://jroller.com/desmax http://www.linkedin.com/in/desmax74 http://wiki.java.net/bin/view/People/MassimilianoDessi http://www.jugsardegna.org/vqwiki/jsp/Wiki?MassimilianoDessi Spring Framework Italian User Group http://it.groups.yahoo.com/group/SpringFramework-it Massimiliano Dessì - desmax74@yahoo.it Lugano - 29/01/2009