Maven, Scala, Spring, AspectJ

流过昼夜 提交于 2019-12-07 05:24:11

问题


Does anyone know if you can weave scala classes at compile time with aspectJ & spring. I have compile time weaving working for all my java classes but I can't seem to get it to work for my scala classes that use @Configurable.


回答1:


For background I have been working on this for a couple of days. What a pain. Anyways here's the answer. Yes it can be done, you just can't use the aspectj maven plugin. You have to use the antrun maven plugin. Happy Scala Coding!

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.6</version>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <target>
                            <taskdef resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties"
                                classpathref="maven.plugin.classpath" />
                            <iajc
                                srcDir="src/main/scala"
                                destDir="target/classes"
                                inpath="target/classes"
                                source="1.6"
                                aspectPath="${org.springframework:spring-aspects:jar}"
                                classpathRef="maven.compile.classpath"
                                Xlint="ignore" />
                        </target>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>org.aspectj</groupId>
                    <artifactId>aspectjrt</artifactId>
                    <version>${aspectj.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.aspectj</groupId>
                    <artifactId>aspectjtools</artifactId>
                    <version>${aspectj.version}</version>
                </dependency>
            </dependencies>
        </plugin>



回答2:


We got compile errors from aspectj-maven-plugin 1.0 that it missed Scala classes. An upgrade from to version 1.4 of the maven plugin solved that.



来源:https://stackoverflow.com/questions/6102518/maven-scala-spring-aspectj

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!