添加外部Jar无效,出现NoClassDefFoundError

问题描述

我创建了一个AOP Library项目,该项目具有“ Before&After”方面注释,我给出了Maven Build,并且成功。我需要在其他服务项目中使用的相同库或注释。我已将库项目Jar添加为构建路径中的外部库。 我可以在“参考库”文件夹中看到Jar文件。 当我运行Service项目时,我收到了NoClassDefFoundError。

import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.**.****.****.aspect.GenesisApiAudit;
import com.**.****.****.aspect.GenesisApiAuditLight;

@RestController
@ComponentScan("com.**.****.****.aspect") //aspect implementation class path
 public class TestAuditController {
    @GetMapping("/hello")
    @GenesisApiAudit
    @GenesisApiAuditLight   
    public String testHello(@RequestParam(defaultValue = "test") String id) {
    
        return "Hello world : ";
    }
}

请参阅下面的Maven Build日志>>>

[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ SpringTestAuditApplication ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to C:\Users\******\Documents\workspace-spring-tool-suite-4-4.7.0.RELEASE\SpringTestAuditApplication\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/******/Documents/workspace-spring-tool-suite-4-4.7.0.RELEASE/SpringTestAuditApplication/src/main/java/com/example/demo/controller/TestAuditController.java:[7,35] package com.jp.genesis.audit.aspect does not exist
[ERROR] /C:/Users/******/Documents/workspace-spring-tool-suite-4-4.7.0.RELEASE/SpringTestAuditApplication/src/main/java/com/example/demo/controller/TestAuditController.java:[8,35] package com.jp.genesis.audit.aspect does not exist
[ERROR] /C:/Users/******/Documents/workspace-spring-tool-suite-4-4.7.0.RELEASE/SpringTestAuditApplication/src/main/java/com/example/demo/controller/TestAuditController.java:[14,10] cannot find symbol
  symbol:   class GenesisApiAudit
  location: class com.example.demo.controller.TestAuditController
[ERROR] /C:/Users/******/Documents/workspace-spring-tool-suite-4-4.7.0.RELEASE/SpringTestAuditApplication/src/main/java/com/example/demo/controller/TestAuditController.java:[15,10] cannot find symbol
  symbol:   class GenesisApiAuditLight
  location: class com.example.demo.controller.TestAuditController
[INFO] 4 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.331 s
[INFO] Finished at: 2020-09-09T17:28:03+05:30
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "pom.xml" could not be activated because it does not exist.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project SpringTestAuditApplication: Compilation failure: Compilation failure: 
[ERROR] /C:/Users/******/Documents/workspace-spring-tool-suite-4-4.7.0.RELEASE/SpringTestAuditApplication/src/main/java/com/example/demo/controller/TestAuditController.java:[7,10] cannot find symbol
[ERROR]   symbol:   class GenesisApiAudit
[ERROR]   location: class com.example.demo.controller.TestAuditController
[ERROR] /C:/Users/******/Documents/workspace-spring-tool-suite-4-4.7.0.RELEASE/SpringTestAuditApplication/src/main/java/com/example/demo/controller/TestAuditController.java:[15,10] cannot find symbol
[ERROR]   symbol:   class GenesisApiAuditLight
[ERROR]   location: class com.example.demo.controller.TestAuditController
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors,re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions,please read the following article

请参阅以下应用程序日志>>>>>

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-09-09 20:10:49.356 ERROR 10748 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'genesisApiAuditAspect': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [com.jp.genesis.audit.aspect.GenesisApiAuditAspect] from ClassLoader [sun.misc.Launcher$AppClassLoader@764c12b6]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:289) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1285) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1200) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
    at com.example.demo.SpringTestAuditApplication.main(SpringTestAuditApplication.java:10) [classes/:na]
Caused by: java.lang.IllegalStateException: Failed to introspect Class [com.jp.genesis.audit.aspect.GenesisApiAuditAspect] from ClassLoader [sun.misc.Launcher$AppClassLoader@764c12b6]
    at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481) ~[spring-core-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321) ~[spring-core-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:267) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    ... 19 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/aspectj/lang/JoinPoint
    at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_211]
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source) ~[na:1.8.0_211]
    at java.lang.Class.getDeclaredMethods(Unknown Source) ~[na:1.8.0_211]
    at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463) ~[spring-core-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    ... 21 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.aspectj.lang.JoinPoint
    at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_211]
    at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_211]
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) ~[na:1.8.0_211]
    at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_211]
    ... 25 common frames omitted

我们如何解决此问题?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...