首页 > 解决方案 > 为什么我的微服务在 Spring Cloud 中没有看到属性?

问题描述

我最近与 Spring Cloud 合作,但遇到了问题!当我尝试启动我的微服务时,出现如下错误:

c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: {"timestamp":1565359011628,"status":500,"error":"Internal Server Error","exception":"java.lang.NoSuchMethodError","message":"org.springframework.boot.builder.SpringApplicationBuilder.<init>([Ljava/lang/Class;)V","path":"/roomservices/dev"}

我的主模块 pom.xml(云和工作微服务的父 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>com.training.mainmodule</groupId>
    <artifactId>mainmodule</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
        <relativePath/>
    </parent>

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

    <modules>
        <module>config</module>
        <module>room-services</module>
    </modules>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.0</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                </plugin>
            </plugins>
        </pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
    </build>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Edgware.SR1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.4.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.4</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.8</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
            <version>2.1.3.RELEASE</version>
        </dependency>
    </dependencies>
</project>

工作微服务 bootstrap.yml:

spring:
  application:
    name: roomservices
  cloud:
    config:
      uri: http://localhost:9000
  profiles:
    active: dev

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

        <parent>
            <groupId>com.training.mainmodule</groupId>
            <artifactId>mainmodule</artifactId>
            <version>1.0-SNAPSHOT</version>
        </parent>

        <groupId>com.training.roomservices</groupId>
        <artifactId>room-services</artifactId>
        <packaging>jar</packaging>
        <version>1.0-SNAPSHOT</version>

        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-jpa</artifactId>
            </dependency>
            <dependency>
                <groupId>postgresql</groupId>
                <artifactId>postgresql</artifactId>
                <version>9.1-901-1.jdbc4</version>
            </dependency>
        </dependencies>
    </project>

云应用 yml:

spring:
  cloud:
    config:
      server:
        native:
          searchLocations: classpath:/shared
  profiles:
    active: native

server:
  port: 9000

云微服务 roomservices.yml 中的工作微服务(称为 roomservices)配置:

server:
  port: 8081

spring:
  jpa:
    hibernate:
      dll-auto: none
    properties:
      hibernate:
        dialect: org.hibernate.dialect.PostgresPlusDialect
        show_sql: true
  datasource:
    driver-class-name: org.postgresql.Driver
    username: postgres
    password: root
    url: jdbc:postgresql://localhost:5432/spring

我的项目结构如下:

在此处输入图像描述

看起来我的客房服务无法在云中找到属性。我错过了什么以及如何解决?

标签: javamavenspring-bootspring-cloud

解决方案


推荐阅读