0

在使用 Spring Boot(v2) 创建 Zipkin 服务器时,我面临着 Whitelabel 错误页面。
"
Whitelabel 错误页面
此应用程序没有 /error 的显式映射,因此您将此视为后备
。Wed Oct 30 11:21:35 IST 2019 出现意外错误(类型=未找到,状态=404)。否消息可用

当我在 Spring Boot 中运行应用程序时,我得到:
“找不到模板位置:classpath:/templates/(请添加一些模板或检查您的 Thymeleaf 配置)”

POM 文件:


    <?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.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>edu.rohit</groupId>
    <artifactId>ZipkinServer</artifactId>
    <version>1</version>
    <name>ZipkinServer</name>
    <description>Demo project for Spring Boot Slueth-Zipkin</description>

    <properties>
        <java.version>1.8</java.version>
        <!-- <spring-cloud.version>Hoxton.RC1</spring-cloud.version> -->
        <spring-cloud.version>2.1.3.RELEASE</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <!-- <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency> -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-rest-hal-browser</artifactId>
        </dependency> -->

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-sleuth</artifactId>
            <version>${spring-cloud.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zipkin</artifactId>
            <version>${spring-cloud.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-sleuth-zipkin</artifactId>
            <version>${spring-cloud.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </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>

    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </repository>
    </repositories>
    </project>    

应用程序属性

    server.port=9411
    #spring.zipkin.baseUrl= http://localhost:9411
    #server.error.whitelabel.enabled=false
    #server.error.path=/error-spring
    # spring.autoconfigure.exclude= org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration
    #spring.freemarker.template-loader-path=classpath:/templates/
    #spring.freemarker.prefer-file-system-access=false
    management.security.enabled=false 

ZipkinServerApplication

    package edu.rohit.ZipkinServer;

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.context.annotation.Bean;

    SpringBootApplication(scanBasePackages={"edu.rohit.ZipkinServer"})

     public class ZipkinServerApplication {

    /*@Bean
    public AlwaysSampler defaultSampler() {
      return new AlwaysSampler();
    }*/


     public static void main(String[] args) {
        SpringApplication.run(ZipkinServerApplication.class, args);
     }

    }   

请帮我解决这个问题

4

3 回答 3

0
I did some study in actuator use in spring boot 2.x.
The actuator use have significant changes. The default endpoint root path is '/actuator' and not'/' as in 1.x. By default only two endpoint(/health, /info) is enable.

#To make all endpoints enable set
    management.endpoints.web.exposure.include=*   
#To specifically enable one endpoint(/beans) set
    management.endpoint.beans.enabled=true 
#Or we can create a WebSecurity bean like this:
    @Bean
    public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http){
          return http.authorizeExchange()
         .pathMatchers("/actuator/**").permitAll()
         .anyExchange().authenticated()
         .and().build();
    }  
#Remember in spring boot 1.x all this issues was resolved by setting the bellow but it is #depreciated in 2.x
    management.security.enabled=false
#By default the base path is '/actuator' but can be changed by setting
    management.endpoints.web.base-path= /<Mypath>

更多详情可以阅读文档https://www.baeldung.com/spring-boot-actuators#boot-2x-actuator

于 2019-11-11T09:50:52.633 回答
0

嗨,如果您的 Spring Cloud 应用程序目标是 Spring Boot 2.x 基础,我建议不要尝试使用 @EnableZipkinServer,因为它不是 java doc 建议的 raccomanded 方式:

形成 Zipkin 基本代码:

/**
 * @deprecated Custom servers are possible, but not supported by the community. Please use our
 * <a href="https://github.com/openzipkin/zipkin#quick-start">default server build</a> first. If you
 * find something missing, please <a href="https://gitter.im/openzipkin/zipkin">gitter</a> us about
 * it before making a custom server.
 *
 * <p>If you decide to make a custom server, you accept responsibility for troubleshooting your
 * build or configuration problems, even if such problems are a reaction to a change made by the
 * OpenZipkin maintainers. In other words, custom servers are possible, but not supported.
 */
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Import(InternalZipkinConfiguration.class)
@Deprecated
public @interface EnableZipkinServer {

}

我谈到了 Spring Boot 应用程序 2.x 系列的个人经验。我的解决方案,用于开发,是使用如下所示的 docker compose(考虑我的应用程序使用 spring cloud stream 来推送 zipkin 跟踪信息:

version: '3.1'

services:
  rabbitmq:
    image: rabbitmq:3-management
    restart: always
    ports:
      - 5672:5672
      - 15671:15671
      - 15672:15672
    networks:
      - messaging

  zipkin-server:
    image: openzipkin/zipkin
    ports:
      - 9065:9411
    environment:
      - zipkin.collector.rabbitmq.uri=amqp://guest:guest@rabbitmq:5672
    networks:
      - messaging

networks:
  messaging:
    driver: bridge

另一方面,如果您的目标是 spring boot 1.5.x,您可以使用传统的嵌入式 zipkin 服务器,如下所示:

聚甲醛:

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>it.valeriovaudi.emarket</groupId>
    <artifactId>zipkin-server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>zipkin-server</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Dalston.RELEASE</spring-cloud.version>
    </properties>

    <dependencies>
        <!-- start web dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- end web dependencies -->

        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-autoconfigure-ui</artifactId>
            <scope>runtime</scope>
        </dependency>


        <!-- start distributed tracing dependencies -->

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-sleuth-zipkin-stream</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-sleuth</artifactId>
        </dependency>
        <!-- EXAMPLE FOR RABBIT BINDING -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream-binder-rabbit</artifactId>
        </dependency>
        <!-- end distributed tracing dependencies -->

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

        <!-- start test dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- end test dependencies -->
    </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>
        <finalName>zipkin-server</finalName>

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

</project>

应用:

打包 it.valeriovaudi.emarket;

@SpringBootApplication
@EnableZipkinStreamServer
public class ZipkinServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(ZipkinServerApplication.class, args);
    }
}

这两种解决方案都对我有用,spring boot 1.5.x 是我的硕士论文的基本 spring boot 版本,而 spring boot 2.x 版本是我个人分布式系统项目的基础版本,我每天都使用它来管理我的角色家庭预算。

我希望这可以帮助你

于 2019-11-07T18:47:05.830 回答
0

仍然使用 2.2.0 父级,我仍然面临可白标错误。我将检查后者,但通过更改 Zipkin 服务器工作的 pom 定义

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.0.RELEASE</version> -->
    <version>1.5.10.RELEASE</version>
    <!-- <relativePath/> lookup parent from repository  -->
</parent>
<groupId>edu.rohit</groupId> 
<artifactId>ZipkinServer</artifactId>  
<version>1</version>  
<name>ZipkinServer</name> 
<description>Demo project for Spring Boot Slueth-Zipkin</description>

<properties>
    <java.version>1.8</java.version>
    <!-- <spring-cloud.version>Hoxton.RC1</spring-cloud.version> -->
    <!-- <spring-cloud.version>2.1.3.RELEASE</spring-cloud.version> -->
    <spring-cloud.version>Edgware.RELEASE</spring-cloud.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <!-- <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web-services</artifactId>
    </dependency> -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-zipkin</artifactId>
        <!-- <version>${spring-cloud.version}</version> -->
    </dependency>
    <dependency>
        <groupId>io.zipkin.java</groupId>
        <artifactId>zipkin-server</artifactId>
        <!-- <version>2.11.7</version> -->
    </dependency>
    <dependency>
        <groupId>io.zipkin.java</groupId>
        <artifactId>zipkin-autoconfigure-ui</artifactId>
        <!-- <version>2.11.7</version> -->
        <scope>runtime</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>

<repositories>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>
</project>

在 zipkinserverapplication 我们需要@Enablezipkinserver

ZipkinServerApplication

package edu.rohit.ZipkinServer;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import zipkin.server.EnableZipkinServer;

@EnableZipkinServer
@SpringBootApplication(scanBasePackages={"edu.rohit.ZipkinServer"})

public class ZipkinServerApplication {

 public static void main(String[] args) {
     SpringApplication.run(ZipkinServerApplication.class, args);
 }
}
于 2019-11-07T18:21:08.370 回答