i have config server with local file
D:\Projects\config-server1\src\main\resources\config\db.properties
driverClassName=com.mysql.driver
username=rootdb
password=mypwddb
And config server application.properties
server.port=8888
spring.profiles.active=native
when i go to http://localhost:8888/db/default server return
{"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"}}]}
next step, i create config client
application.properties of my config client
server.port=8030
spring.application.name=db
spring.profiles.active=default
spring.cloud.config.url=localhost:8888
Main class nothing special
@SpringBootApplication
public class ConfigClient7Application {
public static void main(String[] args) {
SpringApplication.run(ConfigClient7Application.class, args);
}
}
And my controller, when i try to use @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;
}
}
I've tried hundreds of options, but I always get an error
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}"
I spent all day looking for an error, but in the end I didn't find anything Can anyone suggest what the problem is?