0

I have a springboot application which connects both to Elasticsearch and Database. Firstly I used spring-data features such as JpaRepository and ElasticsearchRepository but I would like to start using JdbcTemplate and ElasticSearchTemplate. I deleted all Jpa related services and annotations like @Entity, @Id, and created my own configuration but spring still wants to create EntityManagerFactory and use Hiberante and so on. What shall I do ?

Here is my config

@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);
    }

And my stacktrace

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.
Clyde Barrow
  • 1,924
  • 8
  • 30
  • 60
  • Spring boot by default add this classes via auto configuration. To get rid of such error you need to exclude such class during application bootup. See https://stackoverflow.com/questions/36387265/disable-all-database-related-auto-configuration-in-spring-boot for more information – Shaunak Patel Oct 25 '18 at 16:45
  • @ShaunakPatel I did it that way and I received `org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: At least one JPA metamodel must be present!` – Clyde Barrow Oct 26 '18 at 07:20

0 Answers0