1

Can't make my project compile with Aspectj. There's an issue with Apache CXF that ResourceContext.getResource(SomeClass.class) creates a simple object not a Spring-managed one. So I would like to use weaving and @Configurable to come over this hardship. I got it to work in my test Spring Boot application (I could provide a link on the Github if needed) with the following set up using @Configurable itself and @EnableSpringConfigured:

Here is a snapshot of my pom.xml (Spring version is 4.3.3.RELEASE):

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aspects</artifactId>
    <version>${spring.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-tx</artifactId>
    <version>${spring.version}</version>
</dependency>

and the aspectj-maven-plugin plugin configuration:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.8</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <complianceLevel>1.8</complianceLevel>
        <showWeaveInfo>true</showWeaveInfo>
        <aspectLibraries>
            <aspectLibrary>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aspects</artifactId>
            </aspectLibrary>
        </aspectLibraries>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>compile</goal>
            </goals>
        </execution>
    </executions>
</plugin>

However, when I try to apply the configuration above in the real project in my company I get this weird error:

[ERROR] *path to the java file being weaving* can't determine annotations of missing type javax.transaction.Transactional
[ERROR] when weaving type *the full java class name*
[ERROR] when weaving classes
[ERROR] when weaving
[ERROR] when batch building BuildConfig[null] #Files=27 AopXmls=#0
[ERROR] [Xlint:cantFindType]
[ERROR] error at (no source information available)

My test project doesn't use @Transactional but the real one does. So I've tried to add spring-tx and persistence-api dependencies but nothing works. And the last note: the project is built successful the second time I run mvn install and unsuccessful every time I run mvn clean install.

Any help is much appreciated as I'm really stuck with this error.

Amol Katdare
  • 6,740
  • 2
  • 33
  • 36
Dmitry Senkovich
  • 5,521
  • 8
  • 37
  • 74

1 Answers1

2

Adding the following dependency to the classpath should solve the issue:

<dependency>
    <groupId>javax.transaction</groupId>
    <artifactId>javax.transaction-api</artifactId>
    <version>1.2</version>
    <scope>provided</scope>
</dependency>
StasKolodyuk
  • 4,256
  • 2
  • 32
  • 41
  • Thanks, Stas! It really solved the current problem. Now I can build the project but, unfortunetely, I've found some of Configurable classes makes using of Transactional as well. It causes the following error in runtime: `Caused by: java.lang.IllegalStateException: Post-processor tried to replace bean instance of type *The original class name* with (proxy) object of type *Some weird weaved proxy class name* - not supported for aspect-configured classes!` – Dmitry Senkovich Oct 06 '16 at 13:00
  • @snoopy-whoopy This is a different problem, so open a new question for it. If you found and answer, post your answer as well! – cb4 Nov 02 '16 at 11:06
  • @cb4 Thanks for advice! I found the answer but I am newbie here so should I answer e.g. as a regular answer or as a comment to my problem description? – Dmitry Senkovich Nov 02 '16 at 12:23
  • @snoopy-whoopy You should create a brand new question, then post your answer. It's cleaner that way and will allow others to search for that specific problem. Cheers! – cb4 Nov 02 '16 at 12:27