gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 06:57:43 26 4
gpt4 key购买 nike

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

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com