Announcement Announcement Module
Collapse
No announcement yet.
Advice not used .. what is wrong? pleas help me :) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Advice not used .. what is wrong? pleas help me :)

    Hi,

    I am trying to get AOP to work, but didn’t had success yet.
    It’s just about a simple logging example.

    I would like to get a simple logging message for each execution of a method in “ProjectManagementService? class.

    Unfortunately nothing happens, but there is also no error message.

    Pleas help me . What am I doing wrong?

    Jan

    Created the Advice:
    Code:
    public class ProjectManagementLoggingAdvice implements MethodBeforeAdvice {
    	
    	public void before(Method method, Object[] args, Object target){
    		System.out.println("Servicemethod "+method.getName().toString()+" called!");
    	}
    
    }

    Configuring the applicationContext:
    Code:
    <!-- AOP Beans &#58;&#58; start &#58;&#58; -->
    	
    	<bean id="debugInterceptor" class="org.springframework.aop.interceptor.DebugInterceptor" />
    		
    	<bean id="ProjectServiceProxy" class="org.springframework.aop.framework.ProxyFactoryBean">		
    		<property name="proxyTargetClass">
    			<value>true</value>
    		</property>
    		<property name="optimize">
    			<value>true</value>
    		</property>
    		<property name="target">
    			<ref bean="ProjectManagementService"/>
    		</property>
    		<property name="interceptorNames">	
    			<list>	
    				<value>ProjectManagementLoggingAdvice</value>
    				<value>debugInterceptor</value>				
    			</list>
    		</property>
    	</bean>			
    	
    	<bean id="ProjectManagementLoggingAdvice" class="de.adtech.swd.modules.aop.ProjectManagementLoggingAdvice" />
    	
    	<!-- AOP Beans &#58;&#58; end &#58;&#58; --> 
    			 
    	<!--  ProjectManangement &#58;&#58; start &#58;&#58;  --> 
    	 <bean id="ProjectManagementController" class="de.adtech.swd.frontcontroller.ProjectManagementController">
        	<property name="projectms">
                <ref bean="ProjectManagementService"/>
            </property>       
        </bean>	
    	
    	<bean id="ProjectManagementService" class="de.adtech.swd.model.services.ProjectManagementService" singleton="true">       
        	<property name="projectBDao">
        		<ref bean="ProjectManagementDao"/>
        	</property> 
        	<property name="mediator">
        		<ref bean="ProjectManagementMediator"/>
        	</property>
        </bean>

    Do actions in Controller:
    Code:
    public class ProjectManagementController implements Controller &#123;
    	
    	private ProjectManagementService projectms;
    	
    	public ModelAndView handleRequest&#40;HttpServletRequest arg0, HttpServletResponse arg1&#41; throws Exception &#123;
    				 
    		//fill all needed beans for jsf view
    		projectms.fillProjectBeanList&#40;&#41;;
    		projectms.fillCustomerBeanList&#40;&#41;;
    		//create selectItems for jsf view
    		List customers = projectms.getCustomerBeanList&#40;&#41;;
    		projectms.generateSelectItemsOfCustomers&#40;customers&#41;;			
    						
    		return new ModelAndView&#40;"projectmanagement_list"&#41;;
    	&#125;
    	
    	public void setProjectms&#40;ProjectManagementService pms&#41; &#123;
    		this.projectms = pms;
    	&#125;
    
    &#125;
    Do I have to get Access to the ProjectManagementService by using something like :
    Code:
     ApplicationContext ctx = new   FileSystemXmlApplicationContext&#40;configFile&#41;;
    …ctx.getBean&#40;"ProjectManagementService"&#41;;
    to be able to use Spring AOP ? (I hope not)

  • #2
    You're inserting the service instead of the proxy.

    Change:
    Code:
        <bean id="ProjectManagementController" class="de.adtech.swd.frontcontroller.ProjectManagementController">
           <property name="projectms">
                <ref bean="ProjectManagementService"/>
            </property>       
        </bean>
    to
    Code:
        <bean id="ProjectManagementController" class="de.adtech.swd.frontcontroller.ProjectManagementController">
           <property name="projectms">
                <ref bean="ProjectServiceProxy"/>
            </property>       
        </bean>

    Comment


    • #3
      Yes, that's it .
      It works without problems.
      Thank you very very much

      Jan

      Comment


      • #4
        No problemo.

        Comment

        Working...
        X