Hi,
I am developing a simple portlet using Spring 2.0. I am trying to use AspectJ for logging. I am supposed to use the java j2sdk1.4.2_12. Can somebody let me know what more configuration to print my customised log messages. In this case the System.out.println that i had given in my HelloFromAspectJ isnt getting printed.
I am attaching here with the following,
i) Controller
package com.amp.test.aspect;
import java.util.HashMap;
import org.apache.log4j.Logger;
import java.util.Map;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import org.springframework.web.portlet.mvc.AbstractContro ller;
import org.springframework.web.portlet.ModelAndView;
import java.util.*;
//import java.util.logging.Level;
//import java.util.logging.Logger;
public class GraphController extends AbstractController {
private Logger log = Logger.getLogger(this.getClass());
public ModelAndView handleRenderRequestInternal(RenderRequest request, RenderResponse response) throws Exception {
log.info("######################################## #######################");
log.info("Inside GraphController.handleRenderRequestInternal() ! ! ! ");
log.info("######################################## #####################");
Map model = new HashMap();
return new ModelAndView("WireFrame1", "model", model);
}
}
ii) Aspect
package com.amp.test.aspect;
import java.util.logging.*;
import org.apache.log4j.Logger;
import org.aspectj.lang.*;
import org.aspectj.lang.annotation.Aspect;
public aspect HelloFromAspectJ {
private Logger log = Logger.getLogger(this.getClass());
public void callMeBefore()
{
log.info("**************************************** ************");
log.info("Inside callMeBefore");
log.info("**************************************** ************");
System.out.println("---------------------------------------------------------------------------");
System.out.println("callMeBefore called");
System.out.println("---------------------------------------------------------------------------");
throw new RuntimeException();
}
}
iii) Application-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...ring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- Controllers -->
<bean id="graphController" class="com.amp.test.aspect.GraphController"/>
<bean id="beanAspect" class="com.amp.test.aspect.HelloFromAspectJ">
</bean>
<aop:config>
<aop:aspect id="helloFromAspectJ" ref="beanAspect">
<aopointcut id="method1" expression="execution(* org.springframework.web.servlet.mvc.AbstractContro ller.handleRequest(..))"/>
<aop:before pointcut="execution(* org.springframework.web.servlet.mvc.AbstractContro ller.handleRequest(..))" method="callMeBefore"/>
</aop:aspect>
</aop:config>
<!-- Default View Resolver -->
<bean
class="org.springframework.web.servlet.view.Intern alResourceViewResolver" id="viewResolver">
<property name="cache" value="false"/>
<property name="viewClass" value="org.springframework.web.servlet.view.JstlVi ew"/>
<property name="prefix" value="/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
iv) aspectController-portlet.xml (name of my portlet)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...ring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- Controllers -->
<bean id="graphController" class="com.amp.test.aspect.GraphController"/>
<bean id="beanAspect" class="com.amp.test.aspect.HelloFromAspectJ">
</bean>
<aop:config>
<aop:aspect id="helloFromAspectJ" ref="beanAspect">
<!-- <aopointcut id="callMeBefore" expression="execution(* com.amp.test.aspect.*.*(..))"/> -->
<aopointcut id="callMeBefore" expression="execution(* org.springframework.web.servlet.mvc.AbstractContro ller.handleRequest(..))"/>
<aop:before pointcut="execution(* org.springframework.web.servlet.mvc.AbstractContro ller.handleRequest(..))" method="callMeBefore"/>
<aop:after pointcut="execution(* org.springframework.web.servlet.mvc.AbstractContro ller.handleRequest(..))" method="callMeAfter"/>
</aop:aspect>
</aop:config>
<!-- Handler Mapping -->
<bean id="portletModeHandlerMapping" class="org.springframework.web.portlet.handler.Por tletModeHandlerMapping">
<property name="portletModeMap">
<map>
<entry key="view"><ref bean="graphController"/></entry>
</map>
</property>
</bean>
</beans>
v) logs
2006-11-29 12:40:41,600 INFO [org.springframework.web.portlet.context.XmlPortlet ApplicationContext] - <Bean factory for application context [PortletApplicationContext for namespace 'aspectController-portlet']: org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [graphController,beanAspect,org.springframework.aop .config.internalAutoProxyCreator,callMeBefore,org. springframework.aop.aspectj.AspectJExpressionPoint cut,org.springframework.aop.aspectj.AspectJPointcu tAdvisor,org.springframework.aop.aspectj.AspectJEx pressionPointcut#1,org.springframework.aop.aspectj .AspectJPointcutAdvisor#1,portletModeHandlerMappin g]; parent: org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [graphController,beanAspect,org.springframework.aop .config.internalAutoProxyCreator,callMeBefore,org. springframework.aop.aspectj.AspectJExpressionPoint cut,org.springframework.aop.aspectj.AspectJPointcu tAdvisor,org.springframework.aop.aspectj.AspectJEx pressionPointcut#1,org.springframework.aop.aspectj .AspectJPointcutAdvisor#1,viewResolver]; root of BeanFactory hierarchy>
2006-11-29 12:40:41,600 INFO [org.springframework.web.portlet.context.XmlPortlet ApplicationContext] - <9 beans defined in application context [PortletApplicationContext for namespace 'aspectController-portlet']>
2006-11-29 12:40:41,616 INFO [org.springframework.web.portlet.context.XmlPortlet ApplicationContext] - <Bean 'org.springframework.aop.config.internalAutoProxyC reator' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)>
2006-11-29 12:40:41,616 INFO [org.springframework.web.portlet.context.XmlPortlet ApplicationContext] - <Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMess ageSource@10c986]>
2006-11-29 12:40:41,616 INFO [org.springframework.web.portlet.context.XmlPortlet ApplicationContext] - <Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicatio nEventMulticaster@1e9c3f]>
2006-11-29 12:40:41,616 INFO [org.springframework.beans.factory.support.DefaultL istableBeanFactory] - <Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [graphController,beanAspect,org.springframework.aop .config.internalAutoProxyCreator,callMeBefore,org. springframework.aop.aspectj.AspectJExpressionPoint cut,org.springframework.aop.aspectj.AspectJPointcu tAdvisor,org.springframework.aop.aspectj.AspectJEx pressionPointcut#1,org.springframework.aop.aspectj .AspectJPointcutAdvisor#1,portletModeHandlerMappin g]; parent: org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [graphController,beanAspect,org.springframework.aop .config.internalAutoProxyCreator,callMeBefore,org. springframework.aop.aspectj.AspectJExpressionPoint cut,org.springframework.aop.aspectj.AspectJPointcu tAdvisor,org.springframework.aop.aspectj.AspectJEx pressionPointcut#1,org.springframework.aop.aspectj .AspectJPointcutAdvisor#1,viewResolver]; root of BeanFactory hierarchy]>
2006-11-29 12:40:41,663 INFO [org.springframework.web.portlet.DispatcherPortlet] - <Using context class 'org.springframework.web.portlet.context.XmlPortle tApplicationContext' for portlet 'aspectController'>
2006-11-29 12:40:41,678 INFO [org.springframework.web.portlet.DispatcherPortlet] - <Unable to locate PortletMultipartResolver with name 'portletMultipartResolver': no multipart request handling provided>
2006-11-29 12:40:41,678 INFO [org.springframework.web.portlet.DispatcherPortlet] - <No HandlerAdapters found in portlet 'aspectController': using default>
2006-11-29 12:40:41,678 INFO [org.springframework.web.portlet.DispatcherPortlet] - <FrameworkPortlet 'aspectController': initialization completed in 156 ms>
2006-11-29 12:40:41,678 INFO [org.springframework.web.portlet.DispatcherPortlet] - <Portlet 'aspectController' configured successfully>
2006-11-29 12:40:41,725 INFO [com.amp.test.aspect.GraphController] - <################################################# ##############>
2006-11-29 12:40:41,725 INFO [com.amp.test.aspect.GraphController] - <Inside GraphController.handleRenderRequestInternal() ! ! ! >
2006-11-29 12:40:41,725 INFO [com.amp.test.aspect.GraphController] - <################################################# ############>
2006-11-29 12:40:41,725 WARN [org.springframework.web.servlet.view.InternalResou rceViewResolver] - <View caching is SWITCHED OFF -- DEVELOPMENT SETTING ONLY: This can severely impair performance>


ointcut id="method1" expression="execution(* org.springframework.web.servlet.mvc.AbstractContro ller.handleRequest(..))"/>
Reply With Quote