PDA

View Full Version : Logging and tracing



rossouw
May 12th, 2005, 07:18 AM
Hi there,

I’m trying to put AOP tracing and logging in my project. I’m trying to set up a config file so I can trace and log anything in my application. By that I mean I want to proxy classes and interfaces.
So far I can proxy the intefaces thanx to some tutorial pages but now the classes is a problem. I get some error and I don’t know what the problem is. Here’s a simple example.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC
"-//SPRING//DTD BEAN//EN"
"http&#58;//www.springframework.org/dtd/spring-beans.dtd">

<beans>

<!-- Bean configuration -->
<bean id="businesslogicbean"
class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>IBusinessLogic</value>
</property>
<property name="target">
<ref local="beanTarget"/>
</property>
<property name="interceptorNames">
<list>
<value>theTracingBeforeAdvisor</value>
<value>theTracingAfterAdvisor</value>
<value>theLoggingThrowsAdvisor</value>
</list>
</property>
</bean>

<bean id="businesslogicbean2"
class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target">
<ref local="beanTarget2"/>
</property>
<property name="proxyTargetClass"><value>true</value></property>
<property name="interceptorNames">
<list>
<value>theTracingBeforeAdvisor</value>
<value>theTracingAfterAdvisor</value>
<value>theLoggingThrowsAdvisor</value>
</list>
</property>
</bean>

<!-- Bean Classes -->
<bean id="beanTarget"
class="BusinessLogic"/>

<bean id="beanTarget2"
class="JustAClass"/>

<!-- Advisor pointcut definition for before advice -->
<bean id="theTracingBeforeAdvisor"
class="org.springframework.aop.support.RegexpMethodPointc utAdvisor">
<property name="advice">
<ref local="theTracingBeforeAdvice"/>
</property>
<property name="pattern">
<value>.*</value>
</property>
</bean>

<!-- Advisor pointcut definition for after advice -->
<bean id="theTracingAfterAdvisor"
class="org.springframework.aop.support.RegexpMethodPointc utAdvisor">
<property name="advice">
<ref local="theTracingAfterAdvice"/>
</property>
<property name="pattern">
<value>.*</value>
</property>
</bean>

<bean id="theLoggingThrowsAdvisor"
class="org.springframework.aop.support.RegexpMethodPointc utAdvisor">
<property name="advice">
<ref local="theLoggingThrowsAdvice"/>
</property>
<property name="pattern">
<value>.*</value>
</property>
</bean>

<!-- Advice classes -->
<bean id="theTracingBeforeAdvice"
class="co.za.ep.util.trace.TracingBeforeAdvice"/>
<bean id="theTracingAfterAdvice"
class="co.za.ep.util.trace.TracingAfterAdvice"/>
<bean id="theLoggingThrowsAdvice"
class="co.za.ep.util.log.LoggingThrowsAdvice"/>

</beans>

// the class that implements the interface


public class BusinessLogic
implements IBusinessLogic
&#123;
public void foo&#40;&#41;
&#123;

&#125;

public String stephan&#40;String message, int count&#41;
&#123;
return "WOOT";

&#125;
&#125;

//the plain class


public class JustAClass &#123;

public void printStuff&#40;&#41;&#123;
System.out.println&#40;"Working?"&#41;;

&#125;

&#125;


Why am I getting this error:



org.springframework.beans.factory.BeanCreationExce ption&#58; Error creating bean with name 'businesslogicbean2' defined in file &#91;C&#58;\Eclipse\workspace\TracingAndLogging\springconf ig.xml&#93;&#58; Initialization of bean failed; nested exception is java.lang.IllegalAccessError&#58; null
java.lang.IllegalAccessError
at net.sf.cglib.core.ClassEmitter.setTarget&#40;ClassEmit ter.java&#58;45&#41;
at net.sf.cglib.core.ClassEmitter.<init>&#40;ClassEmitter.java&#58;37&#41;
at net.sf.cglib.core.KeyFactory$Generator.generateCla ss&#40;KeyFactory.java&#58;165&#41;
at net.sf.cglib.core.DefaultGeneratorStrategy.generat e&#40;DefaultGeneratorStrategy.java&#58;25&#41;
at net.sf.cglib.core.AbstractClassGenerator.create&#40;Ab stractClassGenerator.java&#58;215&#41;
at net.sf.cglib.core.KeyFactory$Generator.create&#40;KeyF actory.java&#58;145&#41;
at net.sf.cglib.core.KeyFactory.create&#40;KeyFactory.jav a&#58;117&#41;
at net.sf.cglib.core.KeyFactory.create&#40;KeyFactory.jav a&#58;108&#41;
at net.sf.cglib.proxy.Enhancer.<clinit>&#40;Enhancer.java&#58;69&#41;
at org.springframework.aop.framework.Cglib2AopProxy.g etProxy&#40;Cglib2AopProxy.java&#58;134&#41;
at org.springframework.aop.framework.Cglib2AopProxy.g etProxy&#40;Cglib2AopProxy.java&#58;124&#41;
at org.springframework.aop.framework.ProxyFactoryBean .getSingletonInstance&#40;ProxyFactoryBean.java&#58;241&#41;
at org.springframework.aop.framework.ProxyFactoryBean .setBeanFactory&#40;ProxyFactoryBean.java&#58;201&#41;
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean&#40;AbstractAuto wireCapableBeanFactory.java&#58;301&#41;
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean&#40;AbstractAuto wireCapableBeanFactory.java&#58;223&#41;
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean&#40;AbstractBeanFactory.java&#58;236&#41;
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean&#40;AbstractBeanFactory.java&#58;159&#41;
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons&#40;Defaul tListableBeanFactory.java&#58;255&#41;
at org.springframework.context.support.AbstractApplic ationContext.refresh&#40;AbstractApplicationContext.ja va&#58;317&#41;
at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>&#40;FileSystemXmlApplicationContext.java&#58;82&#41;
at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>&#40;FileSystemXmlApplicationContext.java&#58;67&#41;
at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>&#40;FileSystemXmlApplicationContext.java&#58;58&#41;
at MainApplication.main&#40;MainApplication.java&#58;24&#41;
Exception in thread "main"



I will appreciate any help I can get.

Lawrence Ho
May 12th, 2005, 09:00 AM
I'm not sure if this is the problem, but... have you tried something instead of default package?

Lawrence