我的spring云配置客户端无法解析server1属性。它正在引发“caused by:java.lang.illegalargumentexception:无法解析值“${server1}”中的占位符“server1”
@Controller
@RefreshScope
public class OSLController {
@Value("${server1}")
public String oslServer;
}
以下是配置客户端的bootstrap.properties:
spring.cloud.config.uri=http://localhost:8888
spring.profiles.active=preprod
spring.application.name=osl
下面是配置服务器的配置:application.properties
server.port=8888
spring.profiles.active=native
spring.cloud.config.server.native.searchLocations=classpath:/config/osl,classpath:/osl,classpath:/config
以下是被浏览器点击时的路径:http://localhost:8888/osl/preprod
{
"name": "osl",
"profiles": [
"preprod"
],
"label": null,
"version": null,
"state": null,
"propertySources": [
{
"name": "class path resource [config/osl/osl-preprod.properties",
"source": {
"server1": "preprod"
}
},
{
"name": "class path resource [config/osl/osl.properties",
"source": {
"server1": "common"
}
}
]
}
当config client启动时,它将打印以下日志:
2021-02-27 19:19:06.576 INFO 27040 --- [ main] in.rahul.ConfigClient2Application : Starting ConfigClient2Application using Java 15.0.1 on DESKTOP-CJ4TSGP with PID 27040 (C:\Rahul\Workspace\ConfigClient-2\target\classes started by Rahul in C:\Rahul\Workspace\ConfigClient-2)
2021-02-27 19:19:06.579 INFO 27040 --- [ main] in.rahul.ConfigClient2Application : No active profile set, falling back to default profiles: default
2021-02-27 19:19:07.282 INFO 27040 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=d5ff5a52-737f-3fd5-8528-04cdeb4cd847
2021-02-27 19:19:07.475 INFO 27040 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
我所遵循的教程在启动配置客户机时也会打印以下内容
Fetching config from server at: http://localhost:8888/
上面的消息没有出现在我的配置客户端中,这让我相信配置客户端无法识别配置服务器。
能不能有人来指导这个问题以及如何解决这个问题?如果我能够从浏览器中读取配置,为什么客户端无法连接并解析server1属性。
我用的是windows机器。
谢谢。
暂无答案!
目前还没有任何答案,快来回答吧!