Announcement Announcement Module
Collapse
No announcement yet.
Logging and tracing Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Logging and tracing

    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.
    Code:
    <?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.RegexpMethodPointcutAdvisor">
          <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.RegexpMethodPointcutAdvisor">
          <property name="advice">
             <ref local="theTracingAfterAdvice"/>
          </property>
          <property name="pattern">
             <value>.*</value>
          </property>
       </bean>
       
       <bean id="theLoggingThrowsAdvisor"
          class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
          <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
    Code:
    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
    Code:
    public class JustAClass &#123;
    	
    	public void printStuff&#40;&#41;&#123;
    		System.out.println&#40;"Working?"&#41;;
    		
    	&#125;
    
    &#125;
    Why am I getting this error:

    Code:
    org.springframework.beans.factory.BeanCreationException&#58; Error creating bean with name 'businesslogicbean2' defined in file &#91;C&#58;\Eclipse\workspace\TracingAndLogging\springconfig.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;ClassEmitter.java&#58;45&#41;
    	at net.sf.cglib.core.ClassEmitter.<init>&#40;ClassEmitter.java&#58;37&#41;
    	at net.sf.cglib.core.KeyFactory$Generator.generateClass&#40;KeyFactory.java&#58;165&#41;
    	at net.sf.cglib.core.DefaultGeneratorStrategy.generate&#40;DefaultGeneratorStrategy.java&#58;25&#41;
    	at net.sf.cglib.core.AbstractClassGenerator.create&#40;AbstractClassGenerator.java&#58;215&#41;
    	at net.sf.cglib.core.KeyFactory$Generator.create&#40;KeyFactory.java&#58;145&#41;
    	at net.sf.cglib.core.KeyFactory.create&#40;KeyFactory.java&#58;117&#41;
    	at net.sf.cglib.core.KeyFactory.create&#40;KeyFactory.java&#58;108&#41;
    	at net.sf.cglib.proxy.Enhancer.<clinit>&#40;Enhancer.java&#58;69&#41;
    	at org.springframework.aop.framework.Cglib2AopProxy.getProxy&#40;Cglib2AopProxy.java&#58;134&#41;
    	at org.springframework.aop.framework.Cglib2AopProxy.getProxy&#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.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;301&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;223&#41;
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;236&#41;
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;159&#41;
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons&#40;DefaultListableBeanFactory.java&#58;255&#41;
    	at org.springframework.context.support.AbstractApplicationContext.refresh&#40;AbstractApplicationContext.java&#58;317&#41;
    	at org.springframework.context.support.FileSystemXmlApplicationContext.<init>&#40;FileSystemXmlApplicationContext.java&#58;82&#41;
    	at org.springframework.context.support.FileSystemXmlApplicationContext.<init>&#40;FileSystemXmlApplicationContext.java&#58;67&#41;
    	at org.springframework.context.support.FileSystemXmlApplicationContext.<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.

  • #2
    I'm not sure if this is the problem, but... have you tried something instead of default package?

    Lawrence

    Comment

    Working...
    X