问题标签 [compile-time-weaving]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
4 回答
36279 浏览

java - 为什么 AspectJ 不编译 Spring 的 @Configurable 工作?

更新 5:我已经下载了基于最新 Eclipse 的最新 Spring ToolsSuite IDE。当我将我的项目作为 Maven 项目导入时,Eclipse/STS 似乎使用 Maven 目标来构建我的项目。这意味着 AspectJ 最终在 Eclipse 中正常工作。

更新 4:我最终只使用 Maven + AspectJ 插件进行编译时编织,有效地绕过了 Eclipse 的机制。

更新 3: AspectJ 的 Eclipse 插件似乎破坏了 Eclipse 正确发布到 Tomcat 的能力。只有通过删除项目中的 AspectJ 功能,我才能让它再次正确发布。很烦人。

更新 2:我现在在 Eclipse 中工作。这么说让我很不舒服,但我不知道我是如何从 Eclipse 或 Maven 构建中得到它的。它似乎是编译问题而不是运行时问题。

更新 1:看来我已经通过 Maven 构建让它工作了,但我不知道如何。Eclipse 仍然无法正常工作。我在pom.xml中唯一更改的是添加这些(无关紧要的?)配置参数:

我实际上担心我会重复这个问题,一切都不一致。随着我了解更多,我会不断更新这个问题。

关于 Eclipse,我通过获取我希望编织的二进制方面(在本例中为 spring-aspects.jar)并将其从我的类路径中复制出来,取得了一些进展。然后我将这个现在的外部 jar 添加到我的Aspect Path中。完成此操作后,Eclipse 会在我的代码中正确显示 AspectJ 标记。令人讨厌的是,我不能将spring-aspects.jar留在我的Java 构建路径中,该路径由 Maven 通过 Maven 插件为我维护。然而,出于某种原因,AspectJ 插件看不到二进制方面,除非它们被显式添加到Aspect Path中。


原帖: @Configurable 是一个 Spring 注释,它允许将依赖项注入到 Spring 外部实例化的对象中(例如,通过 Hibernate 或某些工厂类)。

我之前在加载时编织中使用了这个注释,它大部分都有效。有时我会启动并且不会注入任何东西。这个问题产生了这个 StackOverflow 问题。答案并不多,但大多数人建议我尝试编译时编织,因为可靠性更高。

我为 Eclipse 和 Maven 安装了 AspectJ 插件。这两者都产生似乎是正确编译的类。在 AspectJ 编译之前,我在文本编辑器中打开了其中一个类,但没有发现对 AspectJ 的引用。我在 AspectJ 编译后打开它,Eclipse 和 Maven 生成的版本都引用了org.aspectj.weaver.MethodDeclarationLineNumber。这就是为什么我认为它被正确编译的原因。问题是一旦部署,就不会注入任何依赖项。

我的 Spring applicationContext.xml确实包括以下内容:

以上是标记为@Configurable 的类完成DI 所需的全部内容吗?在从加载时编织到编译时编织的转换过程中,我从我的 applicationContext.xml 中删除了META - INF/aop.xml<context:load-time-weaver /> ,并从我的context.xml中删除了Spring 的 Tomcat 编织器。

我该如何进一步调查这个问题?可能的原因是什么?

0 投票
2 回答
2430 浏览

spring - Spring @Configurable with Compile Time Weaving 的启动性能

这是我关于堆栈溢出的第一个问题,所以请善待。

我正在运行一个应用程序

  • 春天 2.5.x
  • 可配置的注释
  • 编译时编织 (CTW)
  • 行家
  • 日食/ajdt

我使用 CTW,一切运行良好。但是如果我第一次实例化一个带注释的类需要很长时间。第二次非常快。

查看第一次调用的分析器堆栈跟踪,我发现 org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesMethodExecution(Method) 使用了 93% 的时间

在第二次调用的堆栈跟踪中,只有 1% 的时间用于此方法。更糟糕的是:第一次调用的时间大约是第二次调用的 10 倍。

我想知道,因为我认为 CTW 不再需要织布工。

但似乎只有当有人在这个类上调用 new 时,Spring 才开始分析原型 bean。它使用 aspectj weaver 来分析需要做什么,并为下一次调用做好准备以加快这个过程。

有没有人有任何加速初始化注释类的第一次调用的经验?

这是我的 pom 的一个片段:

0 投票
1 回答
1576 浏览

spring - 用于带有 Spring 方面的编译时代码检测的 Ant 目标

我使用 Netbeans 6.7 和 Ant 开发了一个 Web 应用程序。webapp 可以工作,但我想重构代码以使用 @Configurable Spring 注释进行更清晰的依赖注入。

我能够让 Spring 方面的加载时编织 (LTW) 间歇工作(请参阅http://forum.springsource.org/showthread.php?t=86904)。

在这一点上,我想在我的工具集上使用编译时编织。

任何人都可以提供一个我可以用来在编译时编织 Spring 方面的 Ant 目标吗?

任何解释如何配置 Netbeans 以在代码编译后立即执行新的 Ant 目标的人都将获得额外的荣誉。

谢谢。

0 投票
4 回答
8728 浏览

java - 如何使用 Java 1.6 Annotation Processing 执行编译时编织?

我创建了一个注解,将它应用到一个 DTO 并编写了一个 Java 1.6 风格的注解处理器。我可以看到如何让 annotationProcessor 编写一个新的源文件,这不是我想要做的,我看不到或知道如何让它修改现有的类(理想情况下只是修改字节码)。修改实际上是相当微不足道的,我希望处理器做的就是插入一个新的 getter 和 setter,其中名称来自正在处理的注释的值。

我的注释处理器看起来像这样;

0 投票
1 回答
2710 浏览

java - Spring with AspectJ compile-time weaving 导致:java.lang.VerifyError: Illegal use of nonvirtual function call

我正在尝试使用 Spring 的 @AspectJ 编译时编织而不是<aop:autoproxy/>它,它会导致一些错误。

首先在编译阶段有一些警告:

然后,当尝试运行一些建议方法的测试时,我得到以下异常:

这是我添加的 Maven 配置,用于尝试使用 AspectJ 编译器进行编译:

我做错了什么以及导致这些错误的原因是什么?

谢谢,尤瓦尔

0 投票
2 回答
5363 浏览

spring - spring aspectj - 编译时编织外部 jar

我有一个使用编译时编织方面的项目。这个项目依赖于另一个项目,它是一个包含为 jar 的项目。我想在编译时在 jar 文件中编织一个类。我怎样才能做到这一点。

谢谢

0 投票
1 回答
14343 浏览

aspectj - AspectJ - 编译时与加载时编织

我无法理解 aspectJ 的编译时和加载时编织以及弄清楚使用什么(以及如何使用 ajc)来编译和构建我的项目。

这是我的项目结构:-

  • TestProject:一个ja​​va服务库。其他一些项目正在使用它。该项目不包含任何方面。

  • TestProject-Aspects :仅包含
    为 TestProject 中的一些类提供建议的方面。我没有使用
    AspectJ5 注释样式,并且我所有的连接点目前都只是在方法
    执行中。

我的问题:

  • ajc vs iajc,它们有什么不同?
  • 有编织的必要吗?

  • 这样的事情会起作用吗?

编译TestProject-Aspects

编译测试项目

  • 我根本不需要使用 javac 吗?我最初用来编译TestProject?
0 投票
1 回答
793 浏览

jpa - Static Weaving for EclipseLink with Eclipse WTP

I've got a project running on Tomcat within Eclipse WTP that deploys with some JPA entities. I would like to enable ChangeTracking on these entities, but this requires enabling weaving. Since Tomcat doesn't allow for dynamic weaving, I need to do this with static weaving.

Is this possible? Eclipse's Dali plugin doesn't seem to have any facility for static weaving.

0 投票
0 回答
592 浏览

ant - iajc fails to weave aspects from a jar but succeedes from class files

So I defined iajc task for my project that does intertype declarations just fine, then there is a separate jar task that creates a project.jar.

Then there is iajc task for junit test target, this task references the project.jar with the goal of weaving its ITDs into test classes like so:

That does not work - compiler produces errors like class "com....Foo" has to implement method doThings() defined in interface Bar

Then I change the <aspectpath> to this:

which is basically using the intermediate class files generated by the compiler and it works great.

Then I find that if I use the outjar option instead of destdir in my iajc task then that jar can be used in <aspectpath>.

So a question and a comment then:

Q. is there some parameter that would make it work with the regular <jar> task?

C. the fact that I have to use outjar is not documented at all - the option to output a jar is mentioned but nowhere does it say that that is the only way to produce a jar that will work.

0 投票
2 回答
2202 浏览

eclipse - 让eclipse使用maven编译/编织我的代码

我正在使用带有 aspectj 的编译时编织来编织 Spring 的事务代码,因此我可以使用@Transactional. 当我从 Eclipse(它使用 aspectj-maven-plugin)内部运行 maven compile 时,eclipse 会同步到 tomcat 服务器并且一切顺利。

但是当 Eclipse 编译(项目-> 自动构建)时,它似乎没有编织 spring 事务代码,我得到了这个错误:

这很烦人,因为我只想编写代码而不是在每次 Eclipse 编译后手动调用 maven compile。

我需要编辑 AJDT 插件的 Aspect Path 或 inPath 吗?为什么 Eclipse 不直接使用 maven 构建?


我在用:

  • Eclipse WTP 靛蓝
  • Spring 3.0.5.Release
  • JDK7 和 Tomcat 7
  • m2eclipse & AJDT 插件

这些是我的 pom.xml 的相关片段: