Spring Cloud 配置客户端无法解析值“${driverClassName}”中的占位符 'driverClassName'

标签 spring server cloud config

我有带有本地文件的配置服务器

D:\Projects\config-server1\src\main\resources\config\db.properties

driverClassName=com.mysql.driver
username=rootdb
password=mypwddb

并配置服务器application.properties

server.port=8888
spring.profiles.active=native

当我访问 http://localhost:8888/db/default 服务器返回时

{"name":"db","profiles":["default"],"label":null,"version":null,"state":null,"propertySources":[{"name":"classpath:/config/db.properties","source":{"driverClassName":"com.mysql.driver","username":"rootdb","password":"qwaszxdb"}},{"name":"classpath:/application.properties","source":{"server.port":"8888","spring.profiles.active":"native"}}]}

下一步,我创建配置客户端

我的配置客户端的application.properties

server.port=8030
spring.application.name=db
spring.profiles.active=default
spring.cloud.config.url=localhost:8888

主类没什么特别的

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

还有我的 Controller ,当我尝试使用@Value()

package com;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DbController {

    @Value("${driverClassName}")
    String driverClassName;

    @GetMapping("/")
    public String myMethod(){
        return driverClassName;
    }
}

我已经尝试了数百种选择,但总是出错

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dbController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'driverClassName' in value "${driverClassName}"

找了一整天的错误,结果什么也没找到 任何人都可以提出问题所在吗?

最佳答案

解决了 我的 pom.xml 和 bootstrap.propertry 是错误的

关于Spring Cloud 配置客户端无法解析值“${driverClassName}”中的占位符 'driverClassName',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64847654/

相关文章:

Java Kryonet 客户端断开连接

node.js - 简化 Node.js 服务器的速率限制算法

spring - 将 bean map 注入(inject) Grails 服务

spring - Spring Hadoop示例Mapreduce抛出auxService:mapreduce_shuffle异常

java - 使用 Spring 托管线程创建 Spring 线程池

docker - "docker images ls"和 "docker image ls"有什么区别?

email - GCP错误报告-通知所有者的电子邮件

api - Whatsapp Cloud API 更新头像

linux - 如何在虚拟机(VM)中崩溃/注入(inject)故障?

java - 使用@CacheEvict中的键清除单个端点的缓存