云客户端配置应用程序无法从Config Server Spring Boot获取属性

Oana-Elena Danescu:

我有一个Web应用程序,我想从Spring Boot使用Server Configuration。这两个应用程序都位于本地主机上。我从头开始制作了前两个应用程序,并且它们可以一起工作,但是当我使用其中具有许多依赖项(不仅是cloud-config和web依赖项)的客户端时,它不再起作用。我怎么知道?我在服务器的属性文件中有一个变量,我尝试在我的客户端中将其与@Value(“ $ {atena}”)一起使用,并且出现错误java.lang.IllegalArgumentException:无法解析值“ $ { atena}”

下图是我的服务器配置应用程序。 在此处输入图片说明

服务器的主类具有以下注释@EnableConfigServer

在atena-config.yml中,我只有变量名:

 atena: 'Hellllloooooo'

bootstrap.yml内容

server:
  port: 9000
spring:
  profiles:
    active: native

和build.gradle依赖项:

dependencies {

    implementation 'org.springframework.cloud:spring-cloud-config-server'
    runtimeOnly 'org.springframework.boot:spring-boot-devtools'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

我确定服务器是正确的,我的客户端出了点问题。

-------------------->客户端

我有一个restcontroller:

@RestController
@RequestMapping("/songs")
    public class SongController {

    @Value("${atena}")
    String variable;

    @GetMapping(value="/check-from")
    public String viewVariable(){
        return variable;
    }
}

在我试图从服务器配置中获取变量。

来自客户端的bootstrap.yml

spring:
  application:
     name: atena-config
   cloud:
     config:
       uri: http://localhost:9000

最后是来自客户端的build.gradle:

    plugins {
    id 'org.springframework.boot' version '2.1.3.RELEASE'
    id 'java'
 }

apply plugin: 'io.spring.dependency-management'

group = 'com'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
}

dependencies {

    compile 'com.google.apis:google-api-services-youtube:v3-rev206-1.25.0'


    implementation 'org.springframework.boot:spring-boot-starter'
    implementation('org.apache.tomcat:tomcat-jdbc:9.0.10')

    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation('org.mybatis:mybatis:3.4.6')
    implementation('org.mybatis:mybatis-spring:1.3.2')

    implementation('org.springframework.boot:spring-boot-starter-jdbc')

    implementation('org.springframework.cloud:spring-cloud-starter-config')
    compile group: 'org.postgresql', name: 'postgresql', version: '42.2.5'
    runtimeOnly 'org.springframework.boot:spring-boot-devtools'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

我真的不知道会发生什么,我很确定这些依赖是问题所在,但是我还没有弄清楚哪个依赖,我不能排除其中的任何一个,因为我在项目中使用了它们。

Oana-Elena Danescu:

没关系。我已经解决了。确实,问题出在我的依赖项上,我的gradle.build出了问题。我用具有所有依赖项的spring初始化器创建了一个新项目,并从那里复制了新的gradle.build,现在它可以正常工作了。

这是客户端的新build.gradle

plugins {
    id 'org.springframework.boot' version '2.1.3.RELEASE'
    id 'java'
}

apply plugin: 'io.spring.dependency-management'

group = 'com'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
    maven { url 'https://repo.spring.io/milestone' }
}
ext {
    set('springCloudVersion', 'Greenwich.RELEASE')
}

dependencies {

    compile 'com.google.apis:google-api-services-youtube:v3-rev206-1.25.0'

    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.0.0'
    implementation 'org.springframework.cloud:spring-cloud-starter-config'
    runtimeOnly 'org.springframework.boot:spring-boot-devtools'
    runtimeOnly 'org.postgresql:postgresql'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Spring Boot Config Client无法从Config Server获取属性

Spring Boot Config Client未从Config Server获取属性

Spring Boot应用程序无法自动连接假客户端

Spring Boot配置客户端属性

如何获取客户端访问Spring Boot应用程序的域名?

用户如何从 Spring Boot 应用程序的其余部分获取客户端?

Spring Boot 应用程序未从 Spring Cloud Config Server 读取属性值

在客户端Spring Boot应用程序上配置自定义OAuth2AccessToken

Spring Cloud Config Server未注册为Spring Boot Admin的客户端

CAS客户端(spring boot + spring security)如何从CAS Server获取更多字段?

将客户端证书添加到Spring Boot应用程序

如何将spring-boot作为客户端应用程序运行?

在Spring Boot应用程序中以嵌入式模式的SymmetricDS作为客户端

在Spring Boot应用程序中进行Hazelcast客户端测试

无法在Spring Boot中获取属性

Spring应用程序-将Amazon S3上的图像获取到客户端

将用户Spring Boot应用程序作为Spring Boot管理员和客户端

在 Spring Config 客户端使用属性

春云配置客户端不获取配置时,Spring Security的是春天的云配置服务器上的活动

Windows上的Docker Engine将忽略Spring Boot Web应用程序的server.port属性

从反应客户端应用程序到 spring-boot 服务器的 HTTP POST 请求返回 400 错误

Spring Cloud Config Server-配置服务器以从一个存储库获取公共属性,而应用程序属性形成另一个存储库

为什么Spring Boot应用程序不断从config服务中获取配置?

为什么我的 Spring Boot Web 应用程序无法加载其配置属性?

Windows Server中的Spring Boot应用程序

无法从JUnit的Spring Boot中读取应用程序属性?

Spring-Boot Cloug Config客户端无法自动接线

无法将Spring Boot应用程序与SQL SERVER数据库连接

无法将Microsoft SQL Server连接到Spring Boot应用程序