Марклоги c с SpringBoot - PullRequest
       7

Марклоги c с SpringBoot

0 голосов
/ 31 марта 2020

Я пытаюсь подключиться к Marklogi c через SpringBootApplication. Как часть приложения spring, свойства определены в файле application.properties. Я дал следующие четыре свойства в файле свойств и пытаюсь использовать его в конфигурации file.Но при запуске приложения оно не распознает базу данных marklogi c и выдает исключение как

"Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class"

mlHost=localhost
mlUsername=admin
mlPassword=admin
mlRestPort=7000


package com.example.springboot;

import com.example.springboot.domain.Product;
import com.marklogic.client.DatabaseClient;
import com.marklogic.client.DatabaseClientFactory;
import com.marklogic.client.document.JSONDocumentManager;
import com.marklogic.client.document.XMLDocumentManager;
import com.marklogic.client.io.JAXBHandle;
import com.marklogic.client.query.QueryManager;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.filter.HTTPDigestAuthFilter;
import com.sun.jersey.api.client.filter.LoggingFilter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import javax.xml.bind.JAXBException;

@Configuration
@EnableAutoConfiguration
@ComponentScan
@SpringBootApplication
public class MarklogicConfiguration {

    @Value("${mlHost}")
    private String host;

    @Value("${mlRestPort}")
    private int port;

    @Value("${mlUsername}")
    private String username;

    @Value("${mlPassword}")
    private String password;

    @Bean
    public DatabaseClient getDatabaseClient() {
        try {
            // TODO: is this really (still) required?
            // configure once before creating a client
            DatabaseClientFactory.getHandleRegistry().register(
                    JAXBHandle.newFactory(Product.class)
            );
        } catch (JAXBException e) {
            e.printStackTrace();
        }

        return DatabaseClientFactory.newClient(host, port, username, password, DatabaseClientFactory.Authentication.DIGEST);
    }

    @Bean
    public QueryManager getQueryManager() {
        return getDatabaseClient().newQueryManager();
    }

    @Bean
    public XMLDocumentManager getXMLDocumentManager() {
        return getDatabaseClient().newXMLDocumentManager();
    }

    @Bean
    public JSONDocumentManager getJSONDocumentManager() {
        return getDatabaseClient().newJSONDocumentManager();
    }

    @Bean
    public String getMarkLogicBaseURL() {
        return String.format("http://%s:%d", host, port);
    }

    @Bean
    public Client getJerseyClient() {
        Client client = Client.create();  // thread-safe
        client.addFilter(new LoggingFilter());
        client.addFilter(new HTTPDigestAuthFilter(username, password));
        return client;
    }


    /**
     * The entrance point to the sample application, starts Spring Boot.
     */
    public static void main(String[] args) throws Exception {
        SpringApplication.run(MarklogicConfiguration.class, args);
    }

}

Ответы [ 2 ]

1 голос
/ 01 апреля 2020

Похоже, ваше приложение Spring Boot ожидает настройки источника данных JPA, но не может найти детали, необходимые для этого. Реализация DataSource в MarkLogi c отсутствует, поэтому вам, вероятно, потребуется отключить этот аспект Spring Boot. См. https://www.baeldung.com/spring-boot-failed-to-configure-data-source для получения информации об исключении DataSourceAutoConfiguration.

0 голосов
/ 03 апреля 2020

Проверьте этот пример (и весь проект) о том, как подключиться к MarkLogi c из SpringBoot:

https://github.com/marklogic-community/grove-spring-boot/blob/master/src/main/java/com/marklogic/grove/boot/auth/AuthController.java

DatabaseClient client;

client = DatabaseClientFactory.newClient(markLogicConfig.getHost(), markLogicConfig.getRestPort(),
                    new DatabaseClientFactory.DigestAuthContext(request.getUsername(), request.getPassword()));

. .. если это сработало, вы должны быть в состоянии сделать это: ...

client.newJSONDocumentManager().read(userDocumentUri, new InputStreamHandle());

userDocumentUri должен быть URI документа, который существует в вашей БД, и роль пользователя может получить к нему доступ ...

...