带有SpringBoot的Marklogic

问题描述 投票:0回答:2

我正在尝试通过SpringBootApplication连接到Marklogic。作为Spring应用程序的一部分,属性在application.properties文件中定义。我在属性文件中提供了以下四个属性,并尝试在配置文件中使用它。运行该应用程序,它无法识别marklogic数据库,并且将异常抛出为

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

}

spring-boot marklogic
2个回答
1
投票
看来您的Spring Boot应用程序期望配置JPA数据源,但是找不到所需的详细信息。没有DataSource的MarkLogic实现,因此您可能需要禁用Spring Boot的这一方面。有关排除DataSourceAutoConfiguration的信息,请参见https://www.baeldung.com/spring-boot-failed-to-configure-data-source

0
投票
检查如何从SpringBoot中连接到MarkLogic的示例(以及整个项目):>

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,并且用户角色可以访问它...
© www.soinside.com 2019 - 2024. All rights reserved.