весна симулируется с hateos - PullRequest
0 голосов
/ 19 марта 2020

Я понимаю больше о весенней загрузке с облаком. Все было нормально, когда я не симулировал зависимость от пом. xml. До тех пор, пока загрузка приложения не начиналась с самого начала, RelProvider не может быть нулевым! и когда я предоставил linkRelProvider для зависимости. ошибка не возникла в MessageResolver

исключение:

Caused by: java.lang.IllegalArgumentException: MessageResolver must not be null!
    at org.springframework.util.Assert.notNull(Assert.java:198) ~[spring-core-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.hateoas.mediatype.hal.Jackson2HalModule$HalLinkListSerializer.<init>(Jackson2HalModule.java:131) ~[spring-hateoas-1.0.3.RELEASE.jar:1.0.3.RELEASE]
    at org.springframework.hateoas.mediatype.hal.Jackson2HalModule$HalLinkListSerializer.<init>(Jackson2HalModule.java:121) ~[spring-hateoas-1.0.3.RELEASE.jar:1.0.3.RELEASE]
    at org.springframework.hateoas.mediatype.hal.Jackson2HalModule$HalHandlerInstantiator.<init>(Jackson2HalModule.java:753) ~[spring-hateoas-1.0.3.RELEASE.jar:1.0.3.RELEASE]
    at org.springframework.hateoas.mediatype.hal.Jackson2HalModule$HalHandlerInstantiator.<init>(Jackson2HalModule.java:738) ~[spring-hateoas-1.0.3.RELEASE.jar:1.0.3.RELEASE]
    at org.springframework.hateoas.mediatype.hal.Jackson2HalModule$HalHandlerInstantiator.<init>(Jackson2HalModule.java:722) ~[spring-hateoas-1.0.3.RELEASE.jar:1.0.3.RELEASE]
    at org.springframework.cloud.openfeign.hateoas.FeignHalAutoConfiguration.halJacksonHttpMessageConverter(FeignHalAutoConfiguration.java:80) ~[spring-cloud-openfeign-core-2.2.1.RELEASE.jar:2.2.1.RELEASE]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_231]

FeignHalAutoConfiguration устанавливает требуемую зависимость, для которой также требуется средство разрешения сообщений, которое я пытаюсь выяснить.

pom. xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.test.spring</groupId>
    <artifactId>spring-examples</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring-examples</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Hoxton.SR1</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-hateoas</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <!-- <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency> -->

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>

        <!-- <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-rest-hal-browser</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.plugin</groupId>
                    <artifactId>spring-plugin-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency> -->

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.6.1</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.6.1</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

appConfig. java

package com.test.spring.springexamples;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.hateoas.client.LinkDiscoverer;
import org.springframework.hateoas.client.LinkDiscoverers;
import org.springframework.hateoas.mediatype.collectionjson.CollectionJsonLinkDiscoverer;
import org.springframework.hateoas.server.LinkRelationProvider;
import org.springframework.hateoas.server.core.AnnotationLinkRelationProvider;
import org.springframework.plugin.core.SimplePluginRegistry;

import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class AppConfig {

    @Bean
    public ResourceBundleMessageSource messageSource() {
        ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
        messageSource.setBasename("message");
        return messageSource;
    }

    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2);
    }

    @Bean
    public LinkDiscoverers discoverers() {
        List<LinkDiscoverer> plugins = new ArrayList<>();
        plugins.add(new CollectionJsonLinkDiscoverer());
        return new LinkDiscoverers(SimplePluginRegistry.create(plugins));

    }

    @Bean
    public LinkRelationProvider linkRelationProvider() {
        return new AnnotationLinkRelationProvider();
    }

}

Пожалуйста, сообщите, что я здесь не так делаю.

1 Ответ

1 голос
/ 19 марта 2020

Если вы добавите debug=true в application.properties, вы увидите в своем отчете

   HypermediaAutoConfiguration.HypermediaConfiguration:
      Did not match:
         - @ConditionalOnMissingBean (types: org.springframework.hateoas.client.LinkDiscoverers; SearchStrategy: all) found beans of type 'org.springframework.hateoas.client.LinkDiscoverers' discoverers (OnBeanCondition)
      Matched:
         - @ConditionalOnClass found required class 'com.fasterxml.jackson.databind.ObjectMapper' (OnClassCondition)

HypermediaConfiguration отступает из-за вашего пользовательского компонента LinkDiscoverers.

Любой удалите это определение компонента или добавьте

@EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL)

В вашем классе приложения.

...