开发者社区> 问答> 正文

Spring AOP切面用注解配置失败——这是什么鬼??报错

十月 16, 2015 7:29:21 上午 org.springframework.context.support.AbstractApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@4b85612c: startup date [Fri Oct 16 07:29:21 CST 2015]; root of context hierarchy
十月 16, 2015 7:29:22 上午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [bean.xml]
十月 16, 2015 7:29:22 上午 org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider registerDefaultFilters
信息: JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
Exception in thread "main" java.lang.IllegalArgumentException
at org.springframework.asm.ClassReader.<init>(Unknown Source)
at org.springframework.asm.ClassReader.<init>(Unknown Source)
at org.springframework.asm.ClassReader.<init>(Unknown Source)
at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:52)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)
at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:101)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:76)
at org.springframework.context.annotation.ConfigurationClassParser.getImports(ConfigurationClassParser.java:298)
at org.springframework.context.annotation.ConfigurationClassParser.getImports(ConfigurationClassParser.java:300)
at org.springframework.context.annotation.ConfigurationClassParser.getImports(ConfigurationClassParser.java:300)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:230)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:153)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:130)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:285)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:223)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:630)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)

at org.itee.test.TestSimpleDial.main(TestSimpleDial.java:9)

注释掉annotation后使用XML配置AOP是运行正确的,但使用annotation注释配置如上报错


展开
收起
爱吃鱼的程序员 2020-06-12 10:42:45 553 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    JDK1.8环境下需使用Spring4.0以上版本

    <projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>


     <groupId>edu.zust</groupId>
     <artifactId>Hibernate</artifactId>
     <version>0.0.1-SNAPSHOT</version>
     <packaging>jar</packaging>


     <name>Hibernate</name>
     <url>http://maven.apache.org</url>


     <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     </properties>


     <dependencies>
      <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>3.8.1</version>
       <scope>test</scope>
      </dependency>
      <dependency>
     <groupId>org.springframework</groupId>
     <artifactId>spring-beans</artifactId>
     <version>3.2.0.RELEASE</version>
    </dependency>
    <dependency>
     <groupId>org.springframework</groupId>
     <artifactId>spring-context</artifactId>
     <version>3.2.0.RELEASE</version>
    </dependency>

    <dependency>
     <groupId>org.springframework</groupId>
     <artifactId>spring-aspects</artifactId>
     <version>3.2.0.RELEASE</version>
    </dependency>
     </dependencies>
    </project>


    改为

    <projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/maven-v4_0_0.xsd">
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.BJ.hello</groupId>
     <artifactId>SImpleD</artifactId>
     <packaging>war</packaging>
     <version>0.0.1-SNAPSHOT</version>
     <name>SImpleDMavenWebapp</name>
     <url>http://maven.apache.org</url>
     <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     </properties>
     <dependencies>
      <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>3.8.1</version>
       <scope>test</scope>
      </dependency>
      <dependency>
     <groupId>org.springframework</groupId>
     <artifactId>spring-beans</artifactId>
     <version>4.1.0.RELEASE</version>
    </dependency>
    <dependency>
     <groupId>org.springframework</groupId>
     <artifactId>spring-context</artifactId>
     <version>4.1.0.RELEASE</version>
    </dependency>

    <dependency>
     <groupId>org.springframework</groupId>
     <artifactId>spring-aspects</artifactId>
     <version>4.1.0.RELEASE</version>
    </dependency>

     </dependencies>
     <build>
      <finalName>SImpleD</finalName>
     </build>
    </project>


    base-package="org.itee"

    试试

    引用来自“jspp”的评论

    base-package="org.itee"

    试试

    项目SImpleD压缩包文件我已上传到百度网盘,分享地址:http://pan.baidu.com/s/1uQAb8望好心人帮助,猪头老师今天下午就要收作业了,我已经尽力了,急急急Liming2015开始拨号。。。
    ----切面id:2------进入aroundadvice!----------


    调用方法之前:预备!


    手机型号:HTCg14,正在接通10086
    around:org.itee.se.PhoneImpl@701a27;call('10086');result:null


    调用方法结束:Over!


    ----切面id:2-------完成aroundadvice!----------


    通话计时:15秒!!!


    没报错啊!有问题 你私聊我 jspp@qq.com

    总之,还是谢谢你的帮助,没有你的反馈,可能我也想不到会是JDK环境的问题XML配置是运行成功的,但注释配置下运行,我这边一直都报错,你是运行的注释配置吗 <beanid="person"class="org.itee.se.PersonImpl"><propertyname="name"value="Liming2015"/><propertyname="phone"ref="phone"/><propertyname="type"value="guest"/></bean><beanid="phone"class="org.itee.se.PhoneImpl"><propertyname="phoneType"value="HTCg14"/></bean><!--<beanid="aspectAdvice"class="org.itee.aoptest.advice.AspectAdvice"/><beanid="aspectAdvice2"class="org.itee.aoptest.advice.AspectAdvice2"/><aop:config><aop:aspectid="springAspect1"ref="aspectAdvice"><aop:pointcutexpression="execution(*org.itee.se.PhoneImpl.call(..))"id="PhoneImpl"/><aop:aroundmethod="doAround"pointcut-ref="PhoneImpl"/></aop:aspect></aop:config><aop:config><aop:aspectid="springAspect2"ref="aspectAdvice2"><aop:aroundmethod="doAround"pointcut="execution(*org.itee.se.PersonImpl.dial(..))"/><aop:beforemethod="doBefore"pointcut="execution(*org.itee.se.PersonImpl.dial(..))"/></aop:aspect></aop:config>--><context:component-scanbase-package="org.itee"/><aop:aspectj-autoproxy/>



    好吧,你打动我了,吾将切换到大卡比windows下去实施最后一次SpringAOP切面注释配置,说多了都是累(泪)呀问题原因已经发现并被解决了,我的本地环境是JDK1.8,Maven配置的Spring框架使用3.2,将Maven中的Spring配置改为4.0及以上,注释配置成功运行
    2020-06-12 10:43:04
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载

相关实验场景

更多