SpringBoot +数据库+ Elasticsearch禁用JPA自动配置

时间:2018-10-25 14:42:36

标签: spring-boot spring-data-jpa spring-data spring-data-elasticsearch

我有一个springboot应用程序,该应用程序同时连接到Elasticsearch和数据库。首先,我使用了诸如JpaRepository和ElasticsearchRepository之类的spring-data功能,但我想开始使用JdbcTemplate和ElasticSearchTemplate。我删除了所有与Jpa相关的服务和注释,例如@ Entity,@ Id,并创建了自己的配置,但是spring仍然想创建EntityManagerFactory并使用Hiberante等。我该怎么办?

这是我的配置

@Bean(name = DE_DATABASE_BEAN_NAME)
    @ConfigurationProperties(prefix = "spring.de")
    @Primary
    public DataSource deDBDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean(name = DE_DATABASE_JDBC_TEMPLATE_NAME)
    public JdbcTemplate jdbcTemplate(@Qualifier(DE_DATABASE_BEAN_NAME) final DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

    @Bean(name = DE_ELASTICSEARCH_TEMPLATE_NAME)
    public ElasticsearchTemplate elasticsearchTemplate() throws UnknownHostException {
        final String server = clusterNodes.split(":")[0];
        final Integer port = Integer.parseInt(clusterNodes.split(":")[1]);
        final Settings settings = Settings.builder().put("cluster.name", clusterName).build();
        final Client client = new PreBuiltTransportClient(settings).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(server), port));
        return new ElasticsearchTemplate(client);
    }

还有我的堆栈跟踪

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Unsatisfied dependency expressed through method 'entityManagerFactory' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'entityManagerFactoryBuilder' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Unsatisfied dependency expressed through method 'entityManagerFactoryBuilder' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaVendorAdapter' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.JpaVendorAdapter]: Factory method 'jpaVendorAdapter' threw exception; nested exception is java.lang.IllegalArgumentException: jdbcUrl is required with driverClassName.

0 个答案:

没有答案
相关问题