我对微型服务很陌生,在那里我必须使用两个服务(这是我在不同的项目中做的)。现在我正在尝试在我的application.yml
文件中设置Eureka配置。
但是,从上面的截图中可以看到,它正在抛出错误:
Nested mappings are not allowed in compact mapping
和
Multiple markers at this line:
- Nested mappings are not allowed in compact mapping
- Implicit keys need to be on a single line
另外,我试过
我在下面分享我的EServerApplication.java
代码:
package com.eserver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class EServerApplication {
public static void main(String[] args) {
SpringApplication.run(EServerApplication.class, args);
}
}
下面是我的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.6.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.eserver</groupId>
<artifactId>e_server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>e_server</name>
<description>This is a microservice for eureka server</description>
<properties>
<java.version>11</java.version>
<spring-cloud.version>2021.0.0</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</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>
但是,当我在application.properties
文件中配置相同的东西时,它工作得很好。
下面是控制台输出:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.6.3)
2022-01-27 14:52:11.965 INFO 14444 --- [ main] com.eserver.EServerApplication : Starting EServerApplication using Java 17.0.1 on SHAHFAISALKHAN with PID 14444 (C:\Users\shahf\Documents\workspace-spring-tool-suite-4-4.13.0.RELEASE\e_server\target\classes started by shahf in C:\Users\shahf\Documents\workspace-spring-tool-suite-4-4.13.0.RELEASE\e_server)
2022-01-27 14:52:11.970 INFO 14444 --- [ main] com.eserver.EServerApplication : No active profile set, falling back to default profiles: default
2022-01-27 14:52:13.550 INFO 14444 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=0f4543fa-8866-3a60-8d6e-f4ead7a36662
2022-01-27 14:52:13.981 INFO 14444 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8761 (http)
2022-01-27 14:52:13.993 INFO 14444 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-01-27 14:52:13.993 INFO 14444 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.56]
2022-01-27 14:52:14.275 INFO 14444 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-01-27 14:52:14.275 INFO 14444 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2203 ms
2022-01-27 14:52:15.013 INFO 14444 --- [ main] c.s.j.s.i.a.WebApplicationImpl : Initiating Jersey application, version 'Jersey: 1.19.4 05/24/2017 03:20 PM'
2022-01-27 14:52:15.089 INFO 14444 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON encoding codec LegacyJacksonJson
2022-01-27 14:52:15.091 INFO 14444 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson
2022-01-27 14:52:15.299 INFO 14444 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml
2022-01-27 14:52:15.300 INFO 14444 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml
2022-01-27 14:52:19.162 INFO 14444 --- [ main] DiscoveryClientOptionalArgsConfiguration : Eureka HTTP Client uses Jersey
2022-01-27 14:52:19.326 WARN 14444 --- [ main] iguration$LoadBalancerCaffeineWarnLogger : Spring Cloud LoadBalancer is currently working with the default cache. You can switch to using Caffeine cache, by adding it and org.springframework.cache.caffeine.CaffeineCacheManager to the classpath.
2022-01-27 14:52:19.393 INFO 14444 --- [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
2022-01-27 14:52:19.494 INFO 14444 --- [ main] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1
2022-01-27 14:52:19.495 INFO 14444 --- [ main] com.netflix.discovery.DiscoveryClient : Client configured to neither register nor query for data.
2022-01-27 14:52:19.525 INFO 14444 --- [ main] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1643275339522 with initial instances count: 0
2022-01-27 14:52:19.657 INFO 14444 --- [ main] c.n.eureka.DefaultEurekaServerContext : Initializing ...
2022-01-27 14:52:19.665 INFO 14444 --- [ main] c.n.eureka.cluster.PeerEurekaNodes : Adding new peer nodes [http://localhost:8761/eureka/]
2022-01-27 14:52:20.036 INFO 14444 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON encoding codec LegacyJacksonJson
2022-01-27 14:52:20.036 INFO 14444 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson
2022-01-27 14:52:20.036 INFO 14444 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml
2022-01-27 14:52:20.036 INFO 14444 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml
2022-01-27 14:52:20.177 INFO 14444 --- [on(3)-127.0.0.1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-01-27 14:52:20.178 INFO 14444 --- [on(3)-127.0.0.1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2022-01-27 14:52:20.333 INFO 14444 --- [ main] c.n.eureka.cluster.PeerEurekaNodes : Replica node URL: http://localhost:8761/eureka/
2022-01-27 14:52:20.377 INFO 14444 --- [ main] c.n.e.registry.AbstractInstanceRegistry : Finished initializing remote region registries. All known remote regions: []
2022-01-27 14:52:20.386 INFO 14444 --- [ main] c.n.eureka.DefaultEurekaServerContext : Initialized
2022-01-27 14:52:20.396 INFO 14444 --- [on(3)-127.0.0.1] o.s.b.a.e.web.EndpointLinksResolver : Exposing 1 endpoint(s) beneath base path '/actuator'
2022-01-27 14:52:20.408 INFO 14444 --- [on(3)-127.0.0.1] o.s.web.servlet.DispatcherServlet : Completed initialization in 230 ms
2022-01-27 14:52:20.547 INFO 14444 --- [ main] o.s.c.n.e.s.EurekaServiceRegistry : Registering application UNKNOWN with eureka with status UP
2022-01-27 14:52:20.551 INFO 14444 --- [ Thread-9] o.s.c.n.e.server.EurekaServerBootstrap : Setting the eureka configuration..
2022-01-27 14:52:20.567 INFO 14444 --- [ Thread-9] o.s.c.n.e.server.EurekaServerBootstrap : isAws returned false
2022-01-27 14:52:20.568 INFO 14444 --- [ Thread-9] o.s.c.n.e.server.EurekaServerBootstrap : Initialized server context
2022-01-27 14:52:20.568 INFO 14444 --- [ Thread-9] c.n.e.r.PeerAwareInstanceRegistryImpl : Got 1 instances from neighboring DS node
2022-01-27 14:52:20.569 INFO 14444 --- [ Thread-9] c.n.e.r.PeerAwareInstanceRegistryImpl : Renew threshold is: 1
2022-01-27 14:52:20.570 INFO 14444 --- [ Thread-9] c.n.e.r.PeerAwareInstanceRegistryImpl : Changing status to UP
2022-01-27 14:52:20.606 INFO 14444 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8761 (http) with context path ''
2022-01-27 14:52:20.607 INFO 14444 --- [ main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 8761
2022-01-27 14:52:20.692 INFO 14444 --- [ Thread-9] e.s.EurekaServerInitializerConfiguration : Started Eureka Server
2022-01-27 14:52:21.438 INFO 14444 --- [ main] com.eserver.EServerApplication : Started EServerApplication in 11.215 seconds (JVM running for 12.441)
2022-01-27 14:53:20.580 INFO 14444 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms
2022-01-27 14:54:20.579 INFO 14444 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms
请指导我如何才能修正application.yml
错误。
编辑:已解决的
我发现这个yml配置文件对每个组件的空白很敏感,因此我在我的程序中更正了它。快把线关了!
发布于 2022-02-10 19:17:37
yaml文件遵循不同的命名约定。下列属性应解决您的问题。
eureka:
client:
register-with-eureka: false
fetch-registry: false
server:
wait-time-in-ms-when-sync-empty: 0
https://stackoverflow.com/questions/70875650
复制相似问题