Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aspectJ' defined in class path resource [ApplicationContext.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is

来源:5-4 Advice应用(上)

qq_慕斯8337134

2016-11-03 22:30

错误信息:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aspectJ' defined in class path resource [ApplicationContext.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.aop.aspectj.AspectJPointcutAdvisor]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting ')' at character position 30

extucion(*com.demo.service.*.*(..))

                              ^


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"

       xmlns:context="http://www.springframework.org/schema/context"

       xmlns:aop="http://www.springframework.org/schema/aop"

       xsi:schemaLocation="http://www.springframework.org/schema/beans

           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

           http://www.springframework.org/schema/context

           http://www.springframework.org/schema/context/spring-context-3.0.xsd

           http://www.springframework.org/schema/aop

           http://www.springframework.org/schema/aop/spring-aop-3.0.xsd

           ">


<bean id="aspectJ" class="com.demo.aspect.AspectJ"></bean>

<bean id="aspectService" class="com.demo.service.AspectService"></bean>

<!-- 切面的配置 -->

<aop:config>

<aop:aspect id="aspectJAOP" ref="aspectJ">

<!-- 切入点的配置 -->

<aop:pointcut expression="extucion(*com.demo.service.*.*(..))" id="aspectPointcut"/>

<!-- beforeAdvice的声明 -->

<aop:before method="before" pointcut-ref="aspectPointcut"/>

</aop:aspect>

</aop:config>


</beans>


AspectJ.java

package com.demo.aspect;


import org.aspectj.lang.annotation.Aspect;



@Aspect

public class AspectJ {

public void before(){

System.out.println("Before");

}

}

AspectService.java

package com.demo.service;


public class AspectService {

public void service(){

System.out.println("AspectService service");

}


}

SpringText.java

package com.demo.test;


import org.springframework.context.ApplicationContext;

import org.springframework.context.support.ClassPathXmlApplicationContext;


import com.demo.aspect.AspectJ;

import com.demo.service.AspectService;


public class SpringTest {


public static void main(String[] args){

ApplicationContext ctx=new ClassPathXmlApplicationContext("ApplicationContext.xml");

AspectService service= (AspectService) ctx.getBean("aspectService");

service.service();

}

}


写回答 关注

1回答

  • WayLeung
    2016-11-12 15:18:11
    已采纳

    你的SpringTest是JUnit单元测试吗 单元测试要写@Test注解然后右键这个方法名 run as JUnit 而且不是在main方法那里运行吧,具体你可以参考老师单元测试的写法

    qq_慕斯8...

    非常感谢!

    2016-11-15 17:57:55

    共 1 条回复 >

Spring入门篇

为您带来IOC和AOP的基本概念及用法,为后续高级课程学习打下基础

268786 学习 · 963 问题

查看课程

相似问题