代码之家  ›  专栏  ›  技术社区  ›  alicjasalamon

向maven项目添加方面

  •  1
  • alicjasalamon  · 技术社区  · 13 年前

    我创造了 aspectJ 独立Maven项目中的类:

    @Aspect
    public class AspectE {
    
        @Pointcut("execution(@EntryPoint * *.*(..))")
        public void defineEntryPoint() {
        }
    
        @Before("defineEntryPoint()")
        public void setThreadName(JoinPoint joinPoint) {
           ...
        }
    
        @After("defineEntryPoint()")
        public void removeThreadName(JoinPoint joinPoint) {
            ...
        }
    }
    

    然后在第二个项目中,我注释了几个方法,并添加到 pom.xml 以下为:

        <dependency>
            <groupId>first-project</groupId>
            <artifactId>first-project</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.7.0</version>
        </dependency>
    

    但仍然有一些方面没有 看见 完全我是不是少了几步?我该怎么办?

    4 回复  |  直到 13 年前
        1
  •  3
  •   Andrei Sfat systemfreund    13 年前
        2
  •  2
  •   Arno    13 年前

    为了用库正确地编织代码,您应该在依赖项中声明它们,并在aspectj weaver中声明它们:

    <dependencies>
        <!-- Aspectj lib  -->
        <dependency>
            <groupId>com.my.group</groupId>
            <artifactId>my-aspect-lib</artifactId>
            <version>1.0</version>
        </dependency>
    
        <!-- Other dependencies -->
    
    </dependencies>
    
    <build>
        <!-- Specific build configuration -->
    
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <configuration>
                    <aspectLibraries>
                        <aspectLibrary>
                            <groupId>com.my.group</groupId>
                            <artifactId>my-aspect-lib</artifactId>
                        </aspectLibrary>
                    </aspectLibraries>
                </configuration>
            </plugin>
    
            <!-- Other plugins configuration -->
    
        </plugins>
    </build>
    
    <!-- Other settings -->
    

        3
  •  1
  •   Frank Pavageau    13 年前

    你必须用代码编织各个方面。这可以通过两种方式实现:

    加载时间编织有点通用,但正确设置可能有点困难。它在启动期间(当编织发生时)消耗更多的CPU,并且还占用内存。 显然,编译时编织在编译过程中消耗了更多的CPU,但你不会为每次重新启动付出代价。

        4
  •  0
  •   user5096772 user5096772    9 年前

    我也有同样的问题。。。但在我添加了这个maven回购后,它就起作用了

    <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjweaver</artifactId>
        <version>1.8.9</version>
    </dependency>