我使用Spring的@Configurable在Dropwizard應用程序中自動裝載用'new'構造的bean。我有一個集成測試,它使用DropwizardAppRule來調出應用程序,並使用aspectj-maven-plugin進行編譯時編織。Spring在運行DropWizard集成測試時未自動配置@ maven build
當我使用IDEA構建並運行集成測試時,bean按預期方式連接並通過測試。
當我運行'mvn clean install'時,這個bean沒有連線,並且測試失敗並帶有NullPointerException。
當我運行'mvn clean install -DskipTests'並啓動應用程序時,這個bean連線正確。
我的問題是爲什麼在'mvn clean install'過程中失敗?
的AspectJ的Maven的插件在這個過程中,源相運行,這樣的類應該集成測試之前,儀器運行:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.8</version>
<configuration>
<complianceLevel>1.8</complianceLevel>
<source>1.8</source>
<target>1.8</target>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
如果我反編譯的類,我可以看到,它確實是儀表。
如果我在@Autowired setter中放置斷點並從IDEA運行集成測試,我可以看到該類正在被Spring連線。
運行'mvn clean install'時,它在setter中根本沒有中斷。
用@Resource替換@Autowired無濟於事。
我有一個具有@EnableSpringConfigured的Spring配置類。我最好的猜測是DropwizardAppRule沒有使用正確的Spring配置,儘管其他彈簧組件正在正確管理。
任何幫助,非常感謝。謝謝。
編輯
我還測試了默認神火(行家3.2.5),並用:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
</plugin>