Why do I get a not exposed to the weaver warnings when making my Spring project?

前端 未结 2 1991
慢半拍i
慢半拍i 2021-02-20 14:38

I seem to get a bunch of warnings like this when I make my Spring project. The project uses Compile Time Weaving and various Spring annotations like Transactional, Autowired, an

相关标签:
2条回答
  • 2021-02-20 15:20

    What are they (What's the effect)?

    It (ajc) is saying that it has found some class that it thinks ought to be or to have been "woven", but that can't be done / hasn't been done.

    Should I be concerned about them?

    Yes. It would mean that the AspectJ compile time weaving won't happen properly; i.e. the annotations on some classes won't take effect.

    What can I do to remove them?

    Change your build configs so that the weaver can find all of the code it needs to weave.

    I'm guessing that your application involves multiple Maven modules. If so, then this Answer has some links to the relevant Eclipse/AspectJ and Maven documentation: https://stackoverflow.com/a/13120709/139985. It seems that the AspectJ Maven plugin needs to be explicitly told where to look for stuff.

    0 讨论(0)
  • 2021-02-20 15:34

    I had a similar problem. On closer inspection, I realized that the warnings were happening during the test-compile phase only, where aspectj was not smart enough to automatically look in the main java source directory as well as in the test source directory. I solved it by splitting the two goals into separate executions, with different configurations. The relevant part of the POM is given below:

            <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>1.10</version>
            <configuration>
              <complianceLevel>1.8</complianceLevel>
              <aspectLibraries>
                <aspectLibrary>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-aspects</artifactId>
                </aspectLibrary>
              </aspectLibraries>
              <source>1.8</source>
              <target>1.8</target>  
            </configuration>
            <executions>
              <execution>
                <id>compile</id>
                <goals>
                  <goal>compile</goal>
                </goals>
              </execution>
              <!-- add explicit instructions for test compile or it can't weave main src classes -->
              <execution>
                <id>test-compile</id>
                <configuration>
                    <goals>
                        <goal>test-compile</goal>           
                        <sources>
                            <basedir>${project.basedir}</basedir>
                            <includes>
                                <include>src/main/java/**/*.java</include>
                                <include>src/test/java/**/*.java</include>
                            </includes>
                        </sources>
                    </goals>
                </configuration>
            </execution>
            </executions>
        </plugin>
    
    0 讨论(0)
提交回复
热议问题