当maven构建运行测试时,Spring引导项目抛出*$$EnhancerBySpringCGLIB不是@AspectJ方面的问题

问题描述 投票:0回答:1

我有一个使用组件(jar)的spring boot应用,它有一些注释和一个 aspectj advice (.aj)。两者都是maven项目,组件(jar)构建运行一切正常,但对于spring应用,我无法成功构建它。

基本上,我的 aspect 是用来记录一些信息的。它寻找一个触发器注解(本例中为@GetMapping),当线程完成处理后,一些收集到的数据会被显示出来。为此,我的Spring应用可能会有一些方法被注解为@Loggable,以确定哪些方法会被收集数据或不被收集。

请注意,我需要的比Spring AOP提供的更多,只是为了举例,我简化了一些东西来重现我的错误。

这些类显然是成功编织的,但当maven运行测试时(应用程序启动),我得到了以下错误。

[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.673 s <<< FAILURE! - in com.rct.aspectj.myaspectjapp.MyaspectjAppApplicationTests
[ERROR] contextLoads  Time elapsed: 0.002 s  <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myAspectResource' defined in file [C:\workspace\myaspectj-app\target\test-classes\com\rct\aspectj\myaspectjapp\resource\MyAspectResource.class]: BeanPostProcessor before instantiation of bean failed; nested exception is java.lang.IllegalArgumentException: Class 'com.rct.aspectj.myaspectjapp.MyaspectjAppApplication$$EnhancerBySpringCGLIB$$12a7b207' is not an @AspectJ aspect
Caused by: java.lang.IllegalArgumentException: Class 'com.rct.aspectj.myaspectjapp.MyaspectjAppApplication$$EnhancerBySpringCGLIB$$12a7b207' is not an @AspectJ aspect

这是我的Spring应用POM和一些类的代码。示例代码可以在这里找到。https:/github.comrctbatistamyaspectj-project。

主计长。

@RestController
@RequestMapping(path = "/aspect")
public class MyAspectResource {

    @Autowired
    private SomeService service;

    @GetMapping(path = "/sayhello/{name}") //@GetMapping annotation that triggers my aspect
    public ResponseEntity<String> teste(@PathVariable String name){
        return ResponseEntity.ok(service.sayHello(name));
    }
}

服务

@Service
public class SomeServiceImpl implements SomeService {

    @Loggable
    @Override
    public String sayHello(String name) {
        try {
            long timeToSleep = new Random().nextInt(1000) + 1000;
            Thread.sleep(timeToSleep);
        } catch (Exception e) {
            e.printStackTrace();
        }   
        return "Hello " + name;
    }
}

弹簧应用POM

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="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.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.1.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.rct.aspectj</groupId>
    <artifactId>myaspectj-app</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>myaspectj-app</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <aspectj.version>1.9.5</aspectj.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.rct.aspectj</groupId>
            <artifactId>myaspectj-lib</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        ...
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.11</version>
                <dependencies>
                    <!-- updagrading the aspectjtools version for aspectj-maven-plugin -->
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjtools</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <complianceLevel>${java.version}</complianceLevel>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <showWeaveInfo>true</showWeaveInfo>
                    <verbose>true</verbose>
                    <encoding>UTF-8</encoding>
                    <weaveDirectories>
                        <weaveDirectory>${project.build.directory}/classes
                        </weaveDirectory>
                    </weaveDirectories>
                    <aspectLibraries>
                        <aspectLibrary>
                            <groupId>com.rct.aspectj</groupId>
                            <artifactId>myaspectj-lib</artifactId>
                        </aspectLibrary>
                    </aspectLibraries>
                </configuration>
                <executions>
                    <execution>
                        <id>weaving-classes</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>compile</goal>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            ...
        </plugins>
    </build>
</project>

更多错误的细节。

[INFO] Scanning for projects...
[INFO] 
[INFO] -------------------< com.rct.aspectj:myaspectj-app >--------------------
[INFO] Building myaspectj-app 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
...
[INFO] 
[INFO] --- aspectj-maven-plugin:1.11:compile (weaving-classes) @ myaspectj-app ---
[INFO] Showing AJC message detail for messages of types: [error, warning, fail]
[INFO] Join point 'method-execution(org.springframework.http.ResponseEntity c.r.a.myaspectjapp.resource.MyAspectResource.teste(java.lang.String))' in Type 'c.r.a.myaspectjapp.resource.MyAspectResource' (MyAspectResource.java:22) advised by before advice from 'c.r.a.core.aspect.LoggableAspect' (myaspectj-lib-0.0.1-SNAPSHOT.jar!LoggableAspect.class:20(from LoggableAspect.aj)) [with runtime test]
[INFO] Join point 'method-execution(org.springframework.http.ResponseEntity c.r.a.myaspectjapp.resource.MyAspectResource.teste(java.lang.String))' in Type 'c.r.a.myaspectjapp.resource.MyAspectResource' (MyAspectResource.java:22) advised by afterReturning advice from 'c.r.a.core.aspect.LoggableAspect' (myaspectj-lib-0.0.1-SNAPSHOT.jar!LoggableAspect.class:26(from LoggableAspect.aj)) [with runtime test]
[INFO] Join point 'method-execution(java.lang.String c.r.a.myaspectjapp.service.SomeServiceImpl.sayHello(java.lang.String))' in Type 'c.r.a.myaspectjapp.service.SomeServiceImpl' (SomeServiceImpl.java:14) advised by around advice from 'c.r.a.core.aspect.LoggableAspect' (myaspectj-lib-0.0.1-SNAPSHOT.jar!LoggableAspect.class:36(from LoggableAspect.aj)) [with runtime test]
[INFO] 
[INFO] --- aspectj-maven-plugin:1.11:test-compile (weaving-classes) @ myaspectj-app ---
[INFO] Showing AJC message detail for messages of types: [error, warning, fail]
[INFO] Join point 'method-execution(java.lang.String c.r.a.myaspectjapp.service.SomeServiceImpl.sayHello(java.lang.String))' in Type 'c.r.a.myaspectjapp.service.SomeServiceImpl' (SomeServiceImpl.java:14) advised by around advice from 'c.r.a.core.aspect.LoggableAspect' (myaspectj-lib-0.0.1-SNAPSHOT.jar!LoggableAspect.class:36(from LoggableAspect.aj)) [with runtime test]
[INFO] Join point 'method-execution(org.springframework.http.ResponseEntity c.r.a.myaspectjapp.resource.MyAspectResource.teste(java.lang.String))' in Type 'c.r.a.myaspectjapp.resource.MyAspectResource' (MyAspectResource.java:22) advised by before advice from 'c.r.a.core.aspect.LoggableAspect' (myaspectj-lib-0.0.1-SNAPSHOT.jar!LoggableAspect.class:20(from LoggableAspect.aj)) [with runtime test]
[INFO] Join point 'method-execution(org.springframework.http.ResponseEntity c.r.a.myaspectjapp.resource.MyAspectResource.teste(java.lang.String))' in Type 'c.r.a.myaspectjapp.resource.MyAspectResource' (MyAspectResource.java:22) advised by afterReturning advice from 'c.r.a.core.aspect.LoggableAspect' (myaspectj-lib-0.0.1-SNAPSHOT.jar!LoggableAspect.class:26(from LoggableAspect.aj)) [with runtime test]
[INFO] 
...
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ myaspectj-app ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running c.r.a.myaspectjapp.MyaspectjAppApplicationTests
18:02:54.568 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
18:02:54.587 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
18:02:54.638 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [c.r.a.myaspectjapp.MyaspectjAppApplicationTests] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
18:02:54.668 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [c.r.a.myaspectjapp.MyaspectjAppApplicationTests], using SpringBootContextLoader
18:02:54.676 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [c.r.a.myaspectjapp.MyaspectjAppApplicationTests]: class path resource [com/rct/aspectj/myaspectjapp/MyaspectjAppApplicationTests-context.xml] does not exist
18:02:54.695 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [c.r.a.myaspectjapp.MyaspectjAppApplicationTests]: class path resource [com/rct/aspectj/myaspectjapp/MyaspectjAppApplicationTestsContext.groovy] does not exist
18:02:54.702 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [c.r.a.myaspectjapp.MyaspectjAppApplicationTests]: no resource found for suffixes {-context.xml, Context.groovy}.
18:02:54.705 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [c.r.a.myaspectjapp.MyaspectjAppApplicationTests]: MyaspectjAppApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
18:02:54.814 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [c.r.a.myaspectjapp.MyaspectjAppApplicationTests]
18:02:54.954 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [C:\workspace\myaspectj-app\target\test-classes\com\rct\aspectj\myaspectjapp\MyaspectjAppApplication.class]
18:02:54.962 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [C:\workspace\myaspectj-app\target\classes\com\rct\aspectj\myaspectjapp\MyaspectjAppApplication.class]
18:02:54.974 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration c.r.a.myaspectjapp.MyaspectjAppApplication for test class c.r.a.myaspectjapp.MyaspectjAppApplicationTests
18:02:55.155 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [c.r.a.myaspectjapp.MyaspectjAppApplicationTests]: using defaults.
18:02:55.156 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
18:02:55.192 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Skipping candidate TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener] due to a missing dependency. Specify custom listener classes or make the default listener classes and their required dependencies available. Offending class: [org/springframework/transaction/interceptor/TransactionAttributeSource]
18:02:55.195 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Skipping candidate TestExecutionListener [org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener] due to a missing dependency. Specify custom listener classes or make the default listener classes and their required dependencies available. Offending class: [org/springframework/transaction/interceptor/TransactionAttribute]
18:02:55.195 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@4310d43, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@54a7079e, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@26e356f0, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@47d9a273, org.springframework.test.context.support.DirtiesContextTestExecutionListener@4b8ee4de, org.springframework.test.context.event.EventPublishingTestExecutionListener@27f981c6, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@1b11171f, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@1151e434, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@2dc54ad4, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@4659191b, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@55634720, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener@4b0d79fc]
18:02:55.222 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@273e7444 testClass = MyaspectjAppApplicationTests, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@7db12bb6 testClass = MyaspectjAppApplicationTests, locations = '{}', classes = '{class c.r.a.myaspectjapp.MyaspectjAppApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@76908cc0, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@49b0b76, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@e056f20, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@6ca8564a, org.springframework.boot.test.context.SpringBootTestArgs@1], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true]], class annotated with @DirtiesContext [false] with mode [null].
18:02:55.294 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.1.RELEASE)

2020-06-15 18:02:55.848  INFO 11328 --- [           main] c.r.a.m.MyaspectjAppApplicationTests     : Starting MyaspectjAppApplicationTests on d4253s000n186 with PID 11328 (started by F929362 in C:\workspace\myaspectj-app)
2020-06-15 18:02:55.852  INFO 11328 --- [           main] c.r.a.m.MyaspectjAppApplicationTests     : No active profile set, falling back to default profiles: default
2020-06-15 18:02:56.908  WARN 11328 --- [           main] o.s.w.c.s.GenericWebApplicationContext   : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myAspectResource' defined in file [C:\workspace\myaspectj-app\target\test-classes\com\rct\aspectj\myaspectjapp\resource\MyAspectResource.class]: BeanPostProcessor before instantiation of bean failed; nested exception is java.lang.IllegalArgumentException: Class 'c.r.a.myaspectjapp.MyaspectjAppApplication$$EnhancerBySpringCGLIB$$12a7b207' is not an @AspectJ aspect
2020-06-15 18:02:56.937  INFO 11328 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-06-15 18:02:56.947 ERROR 11328 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myAspectResource' defined in file [C:\workspace\myaspectj-app\target\test-classes\com\rct\aspectj\myaspectjapp\resource\MyAspectResource.class]: BeanPostProcessor before instantiation of bean failed; nested exception is java.lang.IllegalArgumentException: Class 'c.r.a.myaspectjapp.MyaspectjAppApplication$$EnhancerBySpringCGLIB$$12a7b207' is not an @AspectJ aspect
    ...

2020-06-15 18:02:56.953 ERROR 11328 --- [           main] o.s.test.context.TestContextManager      : Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener@4310d43] to prepare test instance [c.r.a.myaspectjapp.MyaspectjAppApplicationTests@437ebf59]

java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132) ~[spring-test-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:123) ~[spring-test-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:190) ~[spring-test-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:132) ~[spring-test-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:244) ~[spring-test-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:98) [spring-test-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$5(ClassBasedTestDescriptor.java:341) [junit-jupiter-engine-5.6.2.jar:5.6.2]
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.executeAndMaskThrowable(ClassBasedTestDescriptor.java:346) [junit-jupiter-engine-5.6.2.jar:5.6.2]
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$6(ClassBasedTestDescriptor.java:341) [junit-jupiter-engine-5.6.2.jar:5.6.2]
    ...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myAspectResource' defined in file [C:\workspace\myaspectj-app\target\test-classes\com\rct\aspectj\myaspectjapp\resource\MyAspectResource.class]: BeanPostProcessor before instantiation of bean failed; nested exception is java.lang.IllegalArgumentException: Class 'c.r.a.myaspectjapp.MyaspectjAppApplication$$EnhancerBySpringCGLIB$$12a7b207' is not an @AspectJ aspect
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:512) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:893) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) ~[spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) ~[spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
    at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:120) ~[spring-boot-test-2.3.1.RELEASE.jar:2.3.1.RELEASE]
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) ~[spring-test-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124) ~[spring-test-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    ... 65 common frames omitted
Caused by: java.lang.IllegalArgumentException: Class 'c.r.a.myaspectjapp.MyaspectjAppApplication$$EnhancerBySpringCGLIB$$12a7b207' is not an @AspectJ aspect
    at org.springframework.aop.aspectj.annotation.AspectMetadata.<init>(AspectMetadata.java:95) ~[spring-aop-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.aop.aspectj.annotation.BeanFactoryAspectJAdvisorsBuilder.buildAspectJAdvisors(BeanFactoryAspectJAdvisorsBuilder.java:106) ~[spring-aop-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator.findCandidateAdvisors(AnnotationAwareAspectJAutoProxyCreator.java:95) ~[spring-aop-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.shouldSkip(AspectJAwareAdvisorAutoProxyCreator.java:101) ~[spring-aop-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessBeforeInstantiation(AbstractAutoProxyCreator.java:251) ~[spring-aop-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:1141) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:1114) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:506) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    ... 79 common frames omitted

[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.673 s <<< FAILURE! - in c.r.a.myaspectjapp.MyaspectjAppApplicationTests
[ERROR] contextLoads  Time elapsed: 0.002 s  <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myAspectResource' defined in file [C:\workspace\myaspectj-app\target\test-classes\com\rct\aspectj\myaspectjapp\resource\MyAspectResource.class]: BeanPostProcessor before instantiation of bean failed; nested exception is java.lang.IllegalArgumentException: Class 'c.r.a.myaspectjapp.MyaspectjAppApplication$$EnhancerBySpringCGLIB$$12a7b207' is not an @AspectJ aspect
Caused by: java.lang.IllegalArgumentException: Class 'c.r.a.myaspectjapp.MyaspectjAppApplication$$EnhancerBySpringCGLIB$$12a7b207' is not an @AspectJ aspect

[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Errors: 
[ERROR]   MyaspectjAppApplicationTests.contextLoads » IllegalState Failed to load Applic...
[INFO] 
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  17.149 s
[INFO] Finished at: 2020-06-15T18:02:57-03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project myaspectj-app: There are test failures.
[ERROR] 
[ERROR] Please refer to C:\workspace\myaspectj-app\target\surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[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 articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

有人看到任何可能导致异常的错误或缺失吗?

java spring-boot maven aspectj
1个回答
0
投票

你可以添加以下内容来解决这个问题 spring.aop.auto=false 在您的应用程序.属性上

我发现这个在https:/howtodoinjava.comspring-boot2aop-aspectj。

© www.soinside.com 2019 - 2024. All rights reserved.