powered by simpleCommunicator - 2.0.59     © 2025 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Java [игнор отключен] [закрыт для гостей] / Spring AOP (XML-based)
2 сообщений из 2, страница 1 из 1
Spring AOP (XML-based)
    #39608086
yI211
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Изучаю Spring AOP (Schema-based), пытаюсь передать значение параметра в метод «Before advice». По непонятным причинам получаю ошибку «BeanCreationException: Error creating bean with name ...»

Делаю так:
Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
<?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/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
    <aop:config>
     <aop:aspect id="myAspectID" ref="myAspectREF">
      <aop:pointcut id = "myPointcut" 
                    expression = "execution(* myaop2.*.*(..))+args(myParam)"/>
     <aop:before
       pointcut-ref="myPointcut"
       method="myAdviceBefore"
       arg-names="myParam"/> 
     </aop:aspect>
    </aop:config>
    
    <bean id="myWorkClassID" class="myaop2.MyWorkClass">
    </bean>
    
    <bean id="myAspectREF" class="myaop2.MyAspect">
    </bean>
</beans>



Аспект:
Код: java
1.
2.
3.
4.
5.
6.
7.
package myaop2;

public class MyAspect {
 public void myAdviceBefore (String myParam){
  System.out.println("MyAspect.myAdvice_Before: " + myParam);
 }
}



Сообщение об ошибке:
WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.aop.aspectj.AspectJPointcutAdvisor]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.aop.aspectj.AspectJPointcutAdvisor]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:278)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1270)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1127)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at or
..................................................................................................................

В чем причина ошибки ?
...
Рейтинг: 0 / 0
Spring AOP (XML-based)
    #39608126
yI211
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Изучение docs.spring.io помогло выяснить, что причина ошибки состояла в том, что в «expression» надо было символ «+» заменить на «and», т.е pointcut должен быть такой:
Код: xml
1.
2.
<aop:pointcut id = "myPointcut" 
           expression = "execution(* myaop2.MyWorkClass.*(String)) and args(myParam)"/>
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / Spring AOP (XML-based)
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]