'aspect oriented programming concept in spring in java with adding the jar files externally

Whenever I m running the code attached below I m facing this error....

g4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'proxy': FactoryBean threw exception on object creation; nested exception is java.lang.ExceptionInInitializerError
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:150)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:102)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1387)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:244)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1048)
    at Sample.Test.main(Test.java:14)
Caused by: java.lang.ExceptionInInitializerError
    at net.sf.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:166)
    at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
    at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
    at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:144)
    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:116)
    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
    at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:69)
    at org.springframework.aop.framework.Cglib2AopProxy.createEnhancer(Cglib2AopProxy.java:228)
    at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:170)
    at org.springframework.aop.framework.ProxyFactoryBean.getProxy(ProxyFactoryBean.java:362)
    at org.springframework.aop.framework.ProxyFactoryBean.getSingletonInstance(ProxyFactoryBean.java:316)
    at org.springframework.aop.framework.ProxyFactoryBean.getObject(ProxyFactoryBean.java:242)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:143)
    ... 6 more
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @3e92efc3
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
    at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
    at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
    at net.sf.cglib.core.ReflectUtils$2.run(ReflectUtils.java:56)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
    at net.sf.cglib.core.ReflectUtils.<clinit>(ReflectUtils.java:46)
    ... 20 more

BeforeAdviceTest.java

package Sample;

import java.lang.reflect.Method;

import org.springframework.aop.MethodBeforeAdvice;

public class BeforeAdviceTest implements MethodBeforeAdvice {
    @Override  
    public void before(Method method, Object[] args, Object target)throws Throwable {  
        System.out.println("Additional concern " +"before business logic.");  
    }  
}

BuisnessLogic.java

package Sample;

public class BusinessLogic {

    public void implementBusinessLogic(){
        System.out.println("Business logic executed.");
    }
}

Test.java

package Sample;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
 
public class Test {
 public static void main(String[] args) {
  //Get ApplicationContext using spring configuration file.
  ApplicationContext context = 
    new ClassPathXmlApplicationContext("applicationContext.xml");
 
  //Get BusinessLogic bean object from ApplicationContext instance. 
  BusinessLogic businessLogic = 
    (BusinessLogic) context.getBean("proxy", BusinessLogic.class);
 
  //Call implementBusinessLogic method of BusinessLogic bean.
  businessLogic.implementBusinessLogic();
 } 
}

applicationContext.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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
 
   <bean id="businessLogic" 
        class="Sample.BusinessLogic"/>
   <bean id="beforeAdviceTest" 
        class="Sample.BeforeAdviceTest"/>
   <bean id="proxy" 
        class="org.springframework.aop.framework.ProxyFactoryBean">
    <property name="target" ref="businessLogic"></property>  
    <property name="interceptorNames">  
     <list>  
      <value>beforeAdviceTest</value>  
     </list>  
    </property> 
   </bean> 
</beans>


Solution 1:[1]

Issue is not with AOP, For logging, your using log4j dependency, We needs to do some configuration for log4j. May be configuration missed, Causing these issues

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Venkatesh R