Configuring a Service

You've built an audit service that will help you keep track of changes in the application. Now, you need to attach the service to your code. You'll configure the service in this lab.

How do I do that?

The interceptor strategy uses three objects: the target (our façade), a proxy object that Spring creates for you, and an interceptor, which you'll build. Recall that you've got to do three things:

  1. Configure the advice.

  2. Configure the advisor, including a target object, target methods, and the advice.

  3. Configure the target object.

  4. Configure the proxy to use the advisor.

The target object already exists: our façade. The proxy already exists, because you used it for transactions. You need to configure the advice and add it to your proxy. Example 6-3 shows the changes to the context.

Example 6-3. RentABike-servlet.xml

<beans> <bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager"> <property name="sessionFactory"> <ref local="sessionFactory"/> </property> </bean> <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <property name="transactionManager"> <ref local="transactionManager"/> </property> <property name="transactionAttributeSource"> <value> com.springbook.HibernateRentABike.save*=PROPAGATION_REQUIRED </value> </property> </bean> <bean id="loggingBeforeInterceptor" class="com.springbook.interceptors.LoggingBefore"> <property name="factory"> <ref local="sessionFactory"/> ...

Get Spring: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.