Results 1 to 6 of 6

Thread: Help! Cannot get advice to "fire"

  1. #1
    Join Date
    Aug 2004
    Location
    Stockholm
    Posts
    466

    Default Help! Cannot get advice to "fire"

    Here's the setup servlet-context.xml:

    Code:
    <bean id="breakInjector" class="ks.rah.avik2.web.form.support.AddHtmlBreakInterceptor"/>
    	
    	<bean id="breakInjectorTarget" class="ks.rah.avik2.logic.LogicFacadeImpl">
    		<property name="sessionFactory"><ref bean="sessionFactory"/></property>
    	</bean>
    	
    	<!-- Interceptor to inject <br>-tags into output -->
    	<bean id="breakInjectorPointcut" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
    		<property name="advice"><ref local="breakInjector"/></property>
    		<property name="patterns">
    			<list>
    				<value>.*</value>
    			</list>
    		</property>
    	</bean>
    	
    	<bean id="debugInterceptor" class="org.springframework.aop.interceptor.DebugInterceptor">
    	</bean>
    	
    	<bean id="breakInjectorProxy" class="org.springframework.aop.framework.ProxyFactoryBean">		
    		<property name="proxyInterfaces"><value>ks.rah.avik2.logic.LogicFacade</value></property>
    		<property name="target"><ref bean="logic"/></property>
    		<property name="interceptorNames">
    			<list>
    				<value>breakInjector</value>
    				<value>debugInterceptor</value>
    			</list>		
    		</property>
    	</bean>
    The logicImpl (in applicationContext-hibernate)

    Code:
    <bean id="logicImpl" class="ks.rah.avik2.logic.LogicFacadeImpl">
    		<property name="sessionFactory"><ref local="sessionFactory"/></property>
    		<property name="userDao"><ref local="userDao"/></property>
    		<property name="eventDao"><ref local="eventDao"/></property>
    		<property name="posDao"><ref local="positionDao"/></property>
    		<property name="deptDao"><ref local="departmentDao"/></property>
    		<property name="locDao"><ref local="locationDao"/></property>
    		<property name="uiDao"><ref local="uiDao"/></property>
    		<property name="funcDao"><ref local="funcDao"/></property>
    		<property name="tentryDao"><ref local="tentryDao"/></property>
    	</bean>
    Relevant method of interceptor:

    Code:
    public class AddHtmlBreakInterceptor implements MethodInterceptor &#123;
    	
    	public static Logger log = Logger.getLogger&#40;"AddHtmlBreakInterceptor"&#41;;
    	
    	public Object invoke&#40;MethodInvocation invocation&#41; throws Throwable&#123;
    		log.debug&#40;"AddHtmlBreakInterceptor invoked"&#41;;
    		System.out.println&#40;"Holy smoke!"&#41;;
    		return invocation.proceed&#40;&#41;;
    	
    	&#125;
    No traces from log or System.out. No 'Holy smoke!'. Zip. Zero.

    I thought that '.*' meant any method/pattern.

    Help please.
    Sincerely,
    /The Cantor

    "Murphy was an optimist"
    (The O'Toole commentary on Murphy's Law)

  2. #2
    Join Date
    Aug 2004
    Location
    Stockholm
    Posts
    466

    Default Correction

    'logic' should be 'logicImpl'
    It still doesn't work.
    Sincerely,
    /The Cantor

    "Murphy was an optimist"
    (The O'Toole commentary on Murphy's Law)

  3. #3
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    What bean do you access from your client code? breakInjectorProxy?
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  4. #4
    Join Date
    Aug 2004
    Location
    Stockholm
    Posts
    466

    Default

    I access the 'logicImpl' (listed as 'logic' in the first post) which is the main business facade implementation. Hence the

    Code:
    AddHtmlBreakInterceptor
    should fire every time the app hits the database, so there should be a lot of traces. It isn't, of course, invoked directly, but indirectly through a lot of MVC webcontrollers.
    Sincerely,
    /The Cantor

    "Murphy was an optimist"
    (The O'Toole commentary on Murphy's Law)

  5. #5
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    You should be using breakInjectorProxy.
    HTH
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  6. #6
    Join Date
    Aug 2004
    Location
    Stockholm
    Posts
    466

    Default

    You should be using breakInjectorProxy.
    OK....
    I don't understand.
    Isn't the "target" property of the ProxyFactoryBean meant to hide the application from the need to explicitly fetch the ProxyFactoryBean?

    But it works. I apparently have been able to miss this little detail.

    I suggest a minor adjustment to the part of Spring docs that says:
    The "person" bean definition above can be used in place of a Person implementation, as follows:

    Person person = (Person) factory.getBean("person");
    to

    In order to be able to use AOP functionality the "person" bean definition above MUST be used in place of a Person implementation, as follows:

    Person person = (Person) factory.getBean("person");
    Anyway, thanks for your help and patience.
    Sincerely,
    /The Cantor

    "Murphy was an optimist"
    (The O'Toole commentary on Murphy's Law)

Similar Threads

  1. After advice design question
    By drc in forum AOP
    Replies: 2
    Last Post: Sep 29th, 2005, 11:14 PM
  2. May I advice a Servlet?
    By dobri in forum AOP
    Replies: 2
    Last Post: Apr 20th, 2005, 08:20 AM
  3. Replies: 5
    Last Post: Mar 28th, 2005, 08:41 AM
  4. Replies: 9
    Last Post: Dec 6th, 2004, 04:05 PM
  5. Replies: 2
    Last Post: Aug 16th, 2004, 12:38 PM

Posting Permissions

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