为了账号安全,请及时绑定邮箱和手机立即绑定

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

错误信息:

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 回答

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

0 回复 有任何疑惑可以回复我~
#1

qq_慕斯8337134 提问者

非常感谢!
2016-11-15 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

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

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信