1

I have a multi-module Maven project where I am using @Configurable and @Autowired to inject dependencies (CTW). The project have been developed on OS X and Win8, and now I am trying to get it to work with Linux (Ubuntu 14.04). Maven runs just fine but when running the application locally through IntelliJ, the autowired fields are null.

I'm running Tomcat 7 but I have tried with Jetty and I get the same error. Also, @Autowired in @Component annotated classes works fine. Since the project is currently running on both OS X and Win8 using the same(?) IntelliJ configuration, it feels like I've missed something when setting up the environment. Any ideas?

Example class

@Configurable
public class TestClass {

  @Autowired
  private MyRepository repository;

  ...
}

Application context

<context:spring-configured/>
<context:component-scan base-package="com.mycompany"/>
<aop:aspectj-autoproxy/>

aspectj-maven-plugin

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>${aspectj.maven.plugin.version}</version>
    <dependencies>
       <dependency>
          <groupId>org.aspectj</groupId>
          <artifactId>aspectjtools</artifactId>
          <version>${aspectj.version}</version>
       </dependency>
    </dependencies>

    <configuration>
       <complianceLevel>${java.version}</complianceLevel>
       <source>${java.version}</source>
       <target>${java.version}</target>
       <aspectLibraries>
          <aspectLibrary>
             <groupId>org.springframework</groupId>
             <artifactId>spring-aspects</artifactId>
          </aspectLibrary>
       </aspectLibraries>
    </configuration>
    <executions>
       <execution>
          <goals>
             <goal>compile</goal>
             <goal>test-compile</goal>
          </goals>
       </execution>
    </executions>
</plugin>

AspectJ weaveInfo

[INFO] Extending interface set for type 'com.mycompany.TestClass' (TestClass.java) to include 'org.springframework.beans.factory.aspectj.ConfigurableObject' (AnnotationBeanConfigurerAspect.aj)
[INFO] Join point 'initialization(void org.springframework.beans.factory.aspectj.ConfigurableObject.<init>())' in Type 'com.mycompany.TestClass' (TestClass.java:15) advised by before advice from 'org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect' (spring-aspects-3.2.1.RELEASE.jar!AbstractDependencyInjectionAspect.class:78(from AbstractDependencyInjectionAspect.aj)) [with runtime test]
[INFO] Join point 'initialization(void org.springframework.beans.factory.aspectj.ConfigurableObject.<init>())' in Type 'com.mycompany.TestClass' (TestClass.java:15) advised by afterReturning advice from 'org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect' (spring-aspects-3.2.1.RELEASE.jar!AbstractDependencyInjectionAspect.class:87(from AbstractDependencyInjectionAspect.aj)) [with runtime test]
[INFO] Join point 'initialization(void com.mycompany.TestClass.<init>())' in Type 'com.mycompany.TestClass' (TestClass.java:15) advised by afterReturning advice from 'org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect' (spring-aspects-3.2.1.RELEASE.jar!AbstractDependencyInjectionAspect.class:87(from AbstractDependencyInjectionAspect.aj)) [with runtime test]

Update 1 The repositories are Spring Data repositories with @Repository-annotation. However, none of the @Component, @Repository, @Service are autowired into the @Configurable class but they do successfully autowire into @Component-annotated classes.

@Repository
public interface MyRepository extends PagingAndSortingRepository<Person, String>

Update 2 When switching to LTW, the autowiring is successful and the application seems to work as intended. On the other hand, now TomcatInstrumentableClassLoader complains that it can't determine implemented interfaces of missing type com.google.gwt.*

Marcus
  • 153
  • 2
  • 12
  • How do you define `MyRepository` ? – ThomasEdwin Jul 17 '14 at 10:30
  • Is the weaveInfo log from deploying to tomcat/linux? Is runtime weaving an option? – Dirk Lachowski Jul 17 '14 at 11:09
  • @Thomas, I updated the question with repository information. – Marcus Jul 17 '14 at 11:51
  • @DirkLachowski the weaveinfo log is from the aspectj-maven-plugin:compile goal. I would like to avoid changing to LTW if I can (unless I get really desperate, that is) – Marcus Jul 17 '14 at 11:56
  • Do you have `spring-instrument-tomcat-x.x.x.jar` under your `tomcat/lib` directory? – GokcenG Jul 17 '14 at 12:08
  • I have not, but neither does the production machine (which runs fine). As far as I understand, I shouldn't have to if I do the weaving at compile time? – Marcus Jul 17 '14 at 12:19
  • Sad to say, but we have switched from CTW to LTW because `@Configurable` wasn't reliable with CTW. Your should give it a try. Btw: Why are you trying to avoid it? – Dirk Lachowski Jul 17 '14 at 12:30
  • Sorry, I was a bit unclear. I'd like to avoid changing to LTW _at this time_ since we have a deadline coming up. I'm curious though, how is it not reliable? – Marcus Jul 17 '14 at 12:41
  • @DirkLachowski I tried switching to LTW and it seems to have done the trick. If you have any ideas as to why, and care to explain in an answer, I'd be happy to accept it. – Marcus Jul 17 '14 at 13:14
  • 'Reliable' in a 'works sometimes' manner. We had a bunch of `@Configurable` classes, some of them getting autowired, some of them not. Seems to be sort of a limited visibility problem if you have a multi module project. It's been some time since we switched, i will see if i can find any explanation for that... – Dirk Lachowski Jul 17 '14 at 14:23
  • Maybe http://stackoverflow.com/q/828747/1686330 is helpful. – Dirk Lachowski Jul 17 '14 at 14:52

0 Answers0