问题
While creating a Zipkin Server with Spring Boot(v2), I am facing Whitelabel Error Page.
"
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Oct 30 11:21:35 IST 2019
There was an unexpected error (type=Not Found, status=404).
No message available
"
And also while i run the application in spring boot, i get:
" Cannot find template location: classpath:/templates/ (please add some templates or check your
Thymeleaf configuration) "
POM file:
<?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>
application.properties
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);
}
}
Please help me to resolve this
回答1:
Still with using 2.2.0 parent, I still face the whitelable error. I will check on this latter but by changing the pom defination the Zipkin server work
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>
And in zipkinserverapplication we need the @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);
}
}
回答2:
Hi if your spring cloud app target is a Spring Boot 2.x base I suggest to do not try to use the @EnableZipkinServer because it is not a raccomanded way as the java doc suggest:
form the Zipkin base code:
/**
* @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 {
}
I spoke for personal experience with spring boot application 2.x family. The my solution,for development, was use a docker compose like below(consider that my application use spring cloud stream in order to push on zipkin the tracing information:
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
On the other hands if your target is a spring boot 1.5.x you can use the legacy embedded zipkin server like below:
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 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>
Application:
package it.valeriovaudi.emarket;
@SpringBootApplication
@EnableZipkinStreamServer
public class ZipkinServerApplication {
public static void main(String[] args) {
SpringApplication.run(ZipkinServerApplication.class, args);
}
}
both solution works for me, spring boot 1.5.x was the base spring boot version for my master thesis and spring boot 2.x version for a my personal distributed system project that I use every day for my persona family budget management.
I hope that this can help you
回答3:
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>
For more details can read the document https://www.baeldung.com/spring-boot-actuators#boot-2x-actuator
来源:https://stackoverflow.com/questions/58619789/zipkin-server-giving-whitelabel-error-page