Spring @ Configurable / @ Autowired无法在Linux下运行

时间:2014-07-17 10:27:09

标签: java spring maven intellij-idea

我有一个多模块Maven项目,我使用@Configurable@Autowired来注入依赖项(CTW)。该项目是在OS X和Win8上开发的,现在我试图让它与Linux一起工作(Ubuntu 14.04)。 Maven运行得很好但是当通过IntelliJ在本地运行应用程序时,自动连接的字段为空。

我正在运行Tomcat 7,但我尝试过使用Jetty,我也遇到了同样的错误。此外,@Autowired注释类中的@Component工作正常。由于该项目目前使用相同的(?)IntelliJ配置在OS X和Win8上运行,因此在设置环境时我感觉自己错过了一些东西。有什么想法吗?

示例类

@Configurable
public class TestClass {

  @Autowired
  private MyRepository repository;

  ...
}

应用程序上下文

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

AspectJ的行家-插件

<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]

更新1 存储库是带有@Repository - 注释的Spring Data存储库。但是,@Component@Repository@Service都没有自动装入@Configurable类,但它们成功自动装入@Component - 带注释的类。

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

更新2 切换到LTW时,自动装配成功,应用程序似乎按预期工作。另一方面,现在TomcatInstrumentableClassLoader抱怨它无法确定缺失类型com.google.gwt的已实现接口。*

0 个答案:

没有答案