在使用Spring Boot(v2)创建Zipkin服务器时,我遇到了Whitelabel错误页面。
“
白标错误页面
此应用程序没有针对/ error的显式映射,因此您将其视为备用。
IST 2019年10月30日星期三11:21:35
发生意外错误(类型=未找到,状态= 404)。
无可用消息
“
而且,当我在春季启动中运行应用程序时,我得到:
“找不到模板位置:classpath:/ templates /(请添加一些模板或检查您的
Thymeleaf配置)“
<?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
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);
}
}
请帮助我解决此问题
答案 0 :(得分:0)
仍然使用2.2.0父级,我仍然遇到白色错误。 我将检查后者,但通过更改poip定义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 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>
在zipkinserver应用程序中,我们需要@Enablezipkinserver
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);
}
}
答案 1 :(得分:0)
您好,如果您的春季云应用程序目标是Spring Boot 2.x基础,我建议不要尝试使用@EnableZipkinServer,因为它不是Java文档建议的包容性方式:
形成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服务器:
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>
应用程序:
打包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版本是我每天用于角色家庭预算管理的基础。
我希望这可以为您提供帮助
答案 2 :(得分: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