Сервис Spring boot 2 не регистрируется в Eureka - PullRequest
0 голосов

Может кто-нибудь объяснить мне, почему сервис игнорирует регистрационные свойства eureka?

У меня есть простой сервер eureka на локальном хосте: 8761

, и у меня есть служба со следующим application.properties:

server.port=8503
eureka.client.service-url.default-zone=http://localhost:8761/eureka
spring.application.name=dailyoptimizer

my 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.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>ru.mpei</groupId>
    <artifactId>daily-optimizer</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>daily-optimizer</name>
    <description>Executes active power losses optimization during a day</description>

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

    <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>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </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>

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

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

    </dependencies>

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

</project>

трассировка стека не содержит никаких уведомлений об Eureka:

2020-04-02 11:14:40.168  INFO 4092 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:9000
2020-04-02 11:14:42.300  INFO 4092 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Connect Timeout Exception on Url - http://localhost:9000. Will be trying the next url if available
2020-04-02 11:14:42.300  WARN 4092 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://localhost:9000/dailyoptimizer/default": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
2020-04-02 11:14:42.303  INFO 4092 --- [           main] r.m.d.DailyOptimizerApplication          : No active profile set, falling back to default profiles: default
2020-04-02 11:14:43.025  INFO 4092 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-04-02 11:14:43.044  INFO 4092 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 11ms. Found 0 JPA repository interfaces.
2020-04-02 11:14:43.228  INFO 4092 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=ec8f7814-56ab-3659-a038-8542f08caa5e
2020-04-02 11:14:43.670  INFO 4092 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8503 (http)
2020-04-02 11:14:43.684  INFO 4092 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-04-02 11:14:43.684  INFO 4092 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.33]
2020-04-02 11:14:43.885  INFO 4092 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-04-02 11:14:43.886  INFO 4092 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1568 ms
2020-04-02 11:14:44.226  INFO 4092 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2020-04-02 11:14:44.524  INFO 4092 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2020-04-02 11:14:44.581  INFO 4092 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-04-02 11:14:44.741  INFO 4092 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.12.Final
2020-04-02 11:14:44.974  INFO 4092 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-04-02 11:14:45.159  INFO 4092 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2020-04-02 11:14:45.445  INFO 4092 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-04-02 11:14:45.452  INFO 4092 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-04-02 11:14:45.513  WARN 4092 --- [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-04-02 11:14:45.655  INFO 4092 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-04-02 11:14:46.563  INFO 4092 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 2 endpoint(s) beneath base path '/actuator'
2020-04-02 11:14:46.642  INFO 4092 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8503 (http) with context path ''
2020-04-02 11:14:47.267  INFO 4092 --- [           main] r.m.d.DailyOptimizerApplication          : Started DailyOptimizerApplication in 10.211 seconds (JVM running for 12.057)

и наконец в моей IDE я получил предупреждение:

Cannot resolve configuration property 'eureka.client.service-url.default-zone'

код сервиса, если он нужен

@SpringBootApplication
@EnableDiscoveryClient
public class DailyOptimizerApplication {

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

1 Ответ

0 голосов
/ 02 апреля 2020

Попробуйте с этими свойствами ..

eureka.client.registerWithEureka = true
eureka.client.fetchRegistry = true
eureka.client.service-url.defaultZone=http://localhost:8761/eureka

Если не работает, попробуйте добавить эту зависимость вместо зависимости eureka starter в pom. xml

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
...