Ошибка создания bean-компонента с именем bean-id "proxy"

приложение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"
        xsi:schemaLocation="http://www.springframework.org/schema/beans  
                   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    <bean id="obj" class="com.learningspring.aop.aopA"/>
    <bean id="beforeAdvisor" class="com.learningspring.aop.BeforeAdvisor"/>
    <bean id="proxy" class="org.springframework.aop.framework.ProxyFactoryBean">
        <property name="target" ref="obj"/>
        <property name="interceptorNames">
            <list>
                <value>beforeAdvisor</value>
            </list>
        </property>
    </bean>
</beans>

aopA.java

      package com.learningspring.aop;
public class aopA {
    public void m() {
        System.out.println("Actual business logic");
    }
}

BeforeAdvisor.java

      package com.learningspring.aop;

import java.lang.reflect.Method;
import org.springframework.aop.MethodBeforeAdvice;

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

TestAOP.java

      package com.learningspring.aop;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;  

public class TestAOP {
    public static void main(String[] args) {
        Resource r = new ClassPathResource("applicationContext.xml");
        BeanFactory bf = new XmlBeanFactory(r);
        aopA a = (aopA) bf.getBean("proxy");
        a.m();
    }
}

Я запустил указанную выше программу, но получаю следующую ошибку:

      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:301)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
    at com.learningspring.aop.TestAOP.main(TestAOP.java:19)
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)
    ... 5 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 @445b295b
    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)
    ... 19 more

0 ответов

Другие вопросы по тегам