0

Spring Boot でCassandra の hibernate-ogmを構成しようとしていますが、entityManager に透過的に提供される dataSource がなく、実行時に以下のエラーが発生します。

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration required a bean of type 'javax.sql.DataSource' that could not be found.
    - Bean method 'dataSource' not loaded because @ConditionalOnProperty (spring.datasource.jndi-name) did not find property 'jndi-name'
    - Bean method 'dataSource' not loaded because @ConditionalOnBean (types: org.springframework.boot.jta.XADataSourceWrapper; SearchStrategy: all) did not find any beans


Action:

Consider revisiting the conditions above or defining a bean of type 'javax.sql.DataSource' in your configuration.

ケースのワークフローを吹き飛ばす:

spring で関連する jpa の自動構成を無効にすることから始めます。

@Configuration
@ComponentScan
@EnableAutoConfiguration(exclude = {
        DataSourceAutoConfiguration.class,
        DataSourceTransactionManagerAutoConfiguration.class,
        HibernateJpaAutoConfiguration.class
})
public class GsDataApplication {
    public static void main(String[] args) {
        SpringApplication.run(GsDataApplication.class, args);
    }
}

プロジェクトの依存関係は次のとおりです。

dependencies {
    compile project(':shared')

    compile('joda-time:joda-time:2.9.4')
    //compile('org.hibernate:hibernate-core:5.2.2.Final')
    compile('org.hibernate.ogm:hibernate-ogm-cassandra:5.0.1.Final')
    compile('org.hibernate:hibernate-search-orm:5.5.4.Final')
    compile('javax.transaction:jta:1.1')
    compile('org.springframework.data:spring-data-jpa:1.10.4.RELEASE')
    compile('org.springframework.boot:spring-boot-starter-social-facebook')
    compile('org.springframework.boot:spring-boot-starter-social-twitter')
}

持続性構成:

@Configuration
@EnableJpaRepositories(basePackages = {
        "com.gs.gsData.identity"
})
@EnableTransactionManagement
class PersistenceContext {
    @Bean
    LocalContainerEntityManagerFactoryBean entityManagerFactory(Environment env) {
        LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
        entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
        entityManagerFactoryBean.setPackagesToScan("com.gs.gsData.domain");

        Properties jpaProperties = new Properties();
        jpaProperties.put("javax.persistence.transactionType", "resource_local");
        jpaProperties.put("hibernate.ogm.datastore.provider", "cassandra_experimental");
        jpaProperties.put("hibernate.ogm.datastore.host", "127.0.0.1");
        jpaProperties.put("hibernate.ogm.datastore.port", "9042");
        jpaProperties.put("hibernate.ogm.datastore.database", "db-name");
        jpaProperties.put("hibernate.ogm.datastore.username", "cassandra");
        jpaProperties.put("hibernate.ogm.datastore.password", "password");
        jpaProperties.put("hibernate.ogm.datastore.create_database", "true");

        entityManagerFactoryBean.setPersistenceProviderClass(HibernateOgmPersistence.class);
        entityManagerFactoryBean.setJpaProperties(jpaProperties);

        return entityManagerFactoryBean;
    }

    @Bean
    JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
        JpaTransactionManager transactionManager = new JpaTransactionManager();
        transactionManager.setEntityManagerFactory(entityManagerFactory);
        return transactionManager;
    }
}

エンティティのサンプル

@Entity
@Data
@AllArgsConstructor
@Table(name = "`User`")
public class User extends AbstractTiming{
    @Id @GeneratedValue
    private Long id;
    private String firstName, lastName, description;

    public User(){}
}

ADO @リポジトリ

public interface UserDAO extends JpaRepository<User, Long> {
    User findByFirstName(String firstName);
    List<User> findByLastName(String lastName);
}

最後に、Hibernate OGM を参照する DataSource を作成する方法はありますか?

または、直接の dataSource プロバイダーを回避するためのその他のアクション。どんな助けでも大歓迎です!

4

1 に答える 1