Spring Boot 1.3.0.RELEASE の新機能を使用しようとしています- 次の構成を介してプロファイルをアクティブ化しますspring-boot-maven-plugin
。
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<profiles>
<profile>test</profile>
</profiles>
</configuration>
<executions>
<execution>
<id>start-application</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-application</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
しかし、この場合、私の統合テストは失敗し始めます。IllegalArgumentException: Could not resolve placeholder 'spring.mail.host' in string value "${spring.mail.host}"
で定義されたこの変数src/main/resources/application-test.properties
:
spring.profiles: test
spring.mail.host: 127.0.0.1
私のテストは次のようになります。
@ContextConfiguration(
loader = AnnotationConfigContextLoader.class,
initializers = ConfigFileApplicationContextInitializer.class,
classes = TestContext.class
)
public class WhenAnonymousUserRegisterAccount extends AbstractTestNGSpringContextTests {
@Value("${spring.mail.host}")
private String mailHost;
TestContext
PropertySourcesPlaceholderConfigurer
別のプロパティ ファイルでのみ定義します。
興味深いのは、テスト<profiles>
からプロファイルを削除して有効にすると、次のように動作することです。application.properties
spring.profiles.active: test
そのため、Spring を使用していると、ファイルが環境に<profiles>
ロードされないように見えます。application-test.properties
質問:
- バグですか?
- (そうでない場合)ロード
application-test.properties
して使用するようにSpringを構成する方法は<profiles>
? - これらのアプローチが異なるのはなぜですか?