プロジェクトでSpring Bootを使用するためのプロトタイプに取り組んでいます。本番環境に JBoss サーバーがあり、再利用する必要がある persistence.xml が存在するため、Atomikos などの組み込みトランザクション マネージャーを使用して、Undertow 組み込みサーバーに対して統合テストを実行することを考えていました。私のテスト アプリ コンテキスト ファイルには、次の行があります。
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
@EnableAutoConfiguration
@IntegrationTest("server.port:0")
@ActiveProfiles("test")
public abstract class TestApplicationContext {
...
}
また、カスタム テスト構成を次のように追加しました。
@Configuration
public class TestConfiguration {
@Value("${spring.jpa.hibernate.dialect}")
private String dialectClassName;
@Value("${spring.jpa.hibernate.transaction.manager_lookup_class}")
private String transactionManagerClass;
@Bean
public EmbeddedServletContainerFactory servletContainer() {
return new UndertowEmbeddedServletContainerFactory(9000); // Don't know if this can be avoided using some properties
}
@Bean
@ConfigurationProperties(prefix = DataSourceProperties.PREFIX)
public DataSource dataSource() throws Exception {
return DataSourceBuilder.create().build();
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder,
DataSource dataSource) {
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean =
builder.dataSource(dataSource).persistenceUnit("main").build();
Properties additionalProperties = new Properties();
additionalProperties.put("hibernate.dialect", dialectClassName);
additionalProperties.put("hibernate.transaction.manager_lookup_class", transactionManagerClass);
entityManagerFactoryBean.setJpaProperties(additionalProperties);
return entityManagerFactoryBean;
}
@Bean
public PlatformTransactionManager transactionManager() {
// this should not be needed if I have included Atomikos but it seems to pick
// JPA Transaction manager still and fails with the famous NullPointerException at
// CMTTransaction class - because it cannot find a JTA environment
// return new JtaTransactionManager(userTransaction, transactionManager);
}
}
Atomikos の私の gradle インクルードは次のとおりです。
testCompile('org.springframework.boot:spring-boot-starter-jta-atomikos')
Spring Boot 1.2.0-RC2 を使用しています。
誰かが私が間違っていること、またはこれを解決する方法を指摘できますか?
ありがとう、
パディ