Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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, and Configurable.

I have three questions: What are they (What's the effect)? Should I be concerned about them? and "What can I do to remove them?"

ajc: this affected type is not exposed to the weaver: com.myapp.domain.UserEntity [Xlint:typeNotExposedToWeaver]

Let me know what you need to help me solve this issue. I can post relevant parts of the POM file, parts of my Java Spring Configuration files, or whatever. I dont' really know what is required so let me know.

I saw it on the spring forum but that place is a ghost town. Several people have asked this question but there are no answers.

I am using Java Configuration for Spring and CTW.

like image 367
robert_difalco Avatar asked May 11 '13 22:05

robert_difalco


2 Answers

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>
like image 170
Erica Kane Avatar answered Nov 07 '22 09:11

Erica Kane


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.

like image 24
Stephen C Avatar answered Nov 07 '22 09:11

Stephen C