Spring AOP报错

八月 01, 2016 10:08:48 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh

信息: Refreshing org[email protected]277050dc: startup date [Mon Aug 01 22:08:48 CST 2016]; root of context hierarchy

八月 01, 2016 10:08:48 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions

信息: Loading XML bean definitions from class path resource [beans-auto2.xml]

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘studentService‘ defined in class path resource [beans-auto2.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: error at ::0 formal unbound in pointcut

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:471)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700)

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)

at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)

at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)

at com.wyl.test.T.main(T.java:41)

Caused by: 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: error at ::0 formal unbound in pointcut

at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:289)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1114)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1017)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)

at org.springframework.aop.framework.autoproxy.BeanFactoryAdvisorRetrievalHelper.findAdvisorBeans(BeanFactoryAdvisorRetrievalHelper.java:92)

at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findCandidateAdvisors(AbstractAdvisorAutoProxyCreator.java:101)

at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.shouldSkip(AspectJAwareAdvisorAutoProxyCreator.java:103)

at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessBeforeInstantiation(AbstractAutoProxyCreator.java:285)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:958)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:930)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:465)

... 10 more

Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [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.BeanUtils.instantiateClass(BeanUtils.java:164)

at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:125)

at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:281)

... 25 more

Caused by: java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut

at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:302)

at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:211)

at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:197)

at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:186)

at org.springframework.aop.aspectj.AspectJExpressionPointcut.getMethodMatcher(AspectJExpressionPointcut.java:172)

at org.springframework.aop.aspectj.AbstractAspectJAdvice.buildSafePointcut(AbstractAspectJAdvice.java:187)

at org.springframework.aop.aspectj.AspectJPointcutAdvisor.<init>(AspectJPointcutAdvisor.java:51)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)

... 27 more

已经找到原因问题出问题的地方了,但是还不知道为什么会出现这样的情况。

目录结构:

StudentService.java

package com.wyl.service;

/**
 * Student操作类,用于增删改查
 *
 * @author Wei
 *
 */
public interface StudentService {
	/**
	 * 模拟添加学生
	 *
	 * @param name
	 */
	public void addStudent(String name);
}

  

StudentServiceImpl.java

package com.wyl.service.impl;

import com.wyl.service.StudentService;
/**
 * 实现操作类这个接口
 * @author Wei
 *
 */
public class StudentServiceImpl implements StudentService {

	public StudentServiceImpl() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public void addStudent(String name) {
		// TODO Auto-generated method stub
		System.out.println("添加学生:" + name);
	}

}

  

StudentServiceAspect.java

package com.wyl.advice;

/**
 * 切面,为了便于理解,可以直接这样想,用于记日记的类就是一个切面
 *
 * @author Wei
 *
 */
public class StudentServiceAspect {

	/**
	 * 加上了 Joinpoint这个参数就会报错
	 *
	 * @param p
	 */
	// public void doBefore(Joinpoint p){
	// System.out.println("开始添加学生...");
	// }
	/**
	 * 这样就不会报错
	 */
	public void doBefore() {
		System.out.println("开始添加学生...");
	}

}

  

T.java

package com.wyl.test;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.wyl.service.StudentService;

/**
 * 测试类
 *
 * @author Wei
 *
 */
public class T {

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void test() {
		ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("beans-auto2.xml");
		StudentService studentService = (StudentService) ctx.getBean("studentService");
		studentService.addStudent("张三");

	}

	public static void main(String[] args) {
		ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("beans-auto2.xml");
		StudentService studentService = (StudentService) ctx.getBean("studentService");
		studentService.addStudent("李四");
	}

}

  

beans-auto2.xml:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
 4     xmlns:aop="http://www.springframework.org/schema/aop"
 5
 6     xsi:schemaLocation="
 7     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
 8     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
 9         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
10     <context:component-scan base-package="com.wyl"></context:component-scan>
11     <bean id="studentService" class="com.wyl.service.impl.StudentServiceImpl"></bean>
12
13
14     <bean id="studentServiceAspect" class="com.wyl.advice.StudentServiceAspect"></bean>
15
16     <aop:config>
17         <aop:aspect id="studentServiceAspect" ref="studentServiceAspect">
18             <!-- 切点,pointcut,比如加减乘除的service,这就是切面 -->
19             <aop:pointcut expression="execution(* com.wyl.service.*.*(..))"
20                 id="businessService" />
21             <!-- 切面 aspect,具体的日记方法 -->
22             <aop:before method="doBefore" pointcut-ref="businessService" />
23         </aop:aspect>
24
25
26     </aop:config>
27
28 </beans>

具体工程放在qq的微云上,项目名:SpringAOP,地址:https://share.weiyun.com/97bc8712ccad7746538855321e58465e

八月 01, 2016 10:08:48 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh

信息: Refreshing org[email protected]277050dc: startup date [Mon Aug 01 22:08:48 CST 2016]; root of context hierarchy

八月 01, 2016 10:08:48 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions

信息: Loading XML bean definitions from class path resource [beans-auto2.xml]

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘studentService‘ defined in class path resource [beans-auto2.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: error at ::0 formal unbound in pointcut

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:471)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700)

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)

at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)

at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)

at com.wyl.test.T.main(T.java:41)

Caused by: 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: error at ::0 formal unbound in pointcut

at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:289)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1114)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1017)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)

at org.springframework.aop.framework.autoproxy.BeanFactoryAdvisorRetrievalHelper.findAdvisorBeans(BeanFactoryAdvisorRetrievalHelper.java:92)

at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findCandidateAdvisors(AbstractAdvisorAutoProxyCreator.java:101)

at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.shouldSkip(AspectJAwareAdvisorAutoProxyCreator.java:103)

at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessBeforeInstantiation(AbstractAutoProxyCreator.java:285)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:958)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:930)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:465)

... 10 more

Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [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.BeanUtils.instantiateClass(BeanUtils.java:164)

at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:125)

at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:281)

... 25 more

Caused by: java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut

at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:302)

at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:211)

at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:197)

at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:186)

at org.springframework.aop.aspectj.AspectJExpressionPointcut.getMethodMatcher(AspectJExpressionPointcut.java:172)

at org.springframework.aop.aspectj.AbstractAspectJAdvice.buildSafePointcut(AbstractAspectJAdvice.java:187)

at org.springframework.aop.aspectj.AspectJPointcutAdvisor.<init>(AspectJPointcutAdvisor.java:51)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)

... 27 more

时间: 2024-10-20 06:20:15

Spring AOP报错的相关文章

Spring AOP报错处理 Can not set field to $Proxy 在spring中使用事物或AOP遇到的错误

[转] 解决方法: http://forum.springsource.org/showthread.php?85016-IllegalArgumentException-with-ApplicationContextAware-Proxy 在配置文件中加入proxy-target-class="true" <tx:annotation-driven transaction-manager="transactionManager" proxy-target-c

Spring aop报错:com.sun.proxy.$Proxyxxx cannot be cast to yyy

在使用Spring AOP时,遇到如下的错误: Exception in thread "main" java.lang.ClassCastException: com.sun.proxy.$Proxy0 cannot be cast to com.spring.test.setter.Instrumentalist at com.spring.test.setter.test.main(test.java:12) 看报错信息,显示的是动态代理生成的类无法转换到我们自定义的实现类. 解

解决eclipse spring配置报错:cvc-elt.1: Cannot find the declaration of element

解决eclipse spring配置报错:cvc-elt.1: Cannot find the declaration of element 'beans'.Referenced file contains errors (http://www.springframework.org/schema/aop/spring-aop-3.1.xsd). 原因是无法从网络上读取到相应的schema文件,但实际上在浏览器中是可以访问的.却一直在eclipse中显示红叉,当然,并不影响编译打包. 查看所依赖

spring+quartz报错:Table &#39;BANKSTEELERP_OLD.QRTZ_TRIGGERS&#39; doesn&#39;t exist

spring3.2.8 + quartz2.2.1配置到application.xml中 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'startQuertz' defined in class path resource [application.xml]: Invocation of init method failed; nested exception is

使用maven多模块来构建系统时,spring初始化报错的问题

最近在实验maven结构的maven工程时,碰到一个问题,springbean总是初始化失败: Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userMapper' defined in file [D:\workspace\mavenweb\mavenweb-webapp\src\main\webapp\WEB-INF

Spring Boot 报错:Error creating bean with name &#39;entityManagerFactory&#39; defined in class path resource

spring boot 写一个web项目,在使用spring-data-jpa的时候,启动报如下错误: Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.2018-04-02 17:00:47.076 ERROR 4648 --- [ main] o.s.boot.SpringApplication : A

oauth2(spring security)报错method_not_allowed(Request method &#39;GET&#39; not supported)解决方法

报错信息 <MethodNotAllowed> <error>method_not_allowed</error> <error_description>Request method 'GET' not supported</error_description> </MethodNotAllowed> 39是单引号 原因 默认只支持post 解决方法 下载安装postman工具(或其他post工具) 使用post调用 代码增加get的

myeclipse 从svn检出项目后会出现 所有的spring注解报错的问题

myeclipse  从svn检出项目后会出现 所有的spring注解报错的问题  即使更换项目jdk 都不好使. 解决方法如下: 1. 刚检出的项目有可能是 jdk 1.5 一下版本编译的.你只需要切换  编译版本就OK了. 2. 步骤如下: (1)点击项目右键-->选择properties (2)从弹出的窗口中选择 java compiler-->然后选择 适合自己的 jdk 版本就可以了.选择完 apply 一下  选择 yes. 原文地址:https://www.cnblogs.com

Spring Boot 报错记录

Spring Boot 报错记录 由于新建的项目没有配置数据库连接启动报错,可以通过取消自动数据源自动配置来解决 解决方案1: @SpringBootApplication(exclude = DataSourceAutoConfiguration.class) //@SpringBootApplication @MapperScan("com.example.*") //扫描:该包下相应的class,主要是MyBatis的持久化类. 解决方案2: #去配置文件中配置数据库连接参数 #