我有一个使用 github 运行的 Spring Cloud 配置服务器和一个管理用户的 Web 服务。 用于此测试项目的当前版本是:
我有一个使用此配置服务器的服务:
server.port=${PORT:0}
spring.application.name=users-ws
# mysql configuration
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.url=jdbc:mysql://localhost:3306/users?createDatabaseIfNotExist=true
spring.jpa.hibernate.ddl-auto = create
# display sql requests
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
# logging configuration
logging.level.root=WARN
logging.level.sql=INFO
logging.level.web=WARN
logging.level.fr.dsidiff=WARN
logging.level.org.hibernate.SQL=TRACE
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
logging.file.name=webapps-logs/users-ws.logs
logging.logback.rollingpolicy.file-name-pattern=webapps-logs/archived/users-ws.%d{yyyy-MM-dd}.%i.log
logging.logback.rollingpolicy.max-history=5
logging.logback.rollingpolicy.max-file-size=250MB
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} %green([%thread]) %highlight(%level) %logger{36} - %msg%n
logging.pattern.file=%d{dd-MM-yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M - %msg%n
token.expirationTime=3600000
users.ws.accountLock=2
我还添加了 bootstrap.properties (即使是可选的):
spring.config.name=springCloudConfigServer
spring.config.import=optional:configserver:http://localhost:8012
现在在另一边,我配置了我的配置服务器以从远程 git 存储库获取配置:
spring.application.name=springCloudConfigServer
server.port=8012
# local or repo git
# github
spring.profiles.active=git
spring.cloud.config.server.git.uri=https://github.com/me/config-server
[email protected]
spring.cloud.config.server.git.password=****mytoken***
spring.cloud.config.server.git.clone-on-start=true
spring.cloud.config.server.git.force-pull=true
spring.cloud.config.server.git.default-label=master
#https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_server.html
spring.cloud.config.server.git.search-paths=dsipilot**
我在远程服务器上推送了一个 application.properties ,其中包含一些我想要覆盖用于测试目的的基本参数,例如,我更改了以下信息:
token.expirationTime=7200000
users.ws.accountLock=5
我的问题是启动时,我的用户网络服务崩溃:
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
显然,应用程序无法启动,因为它没有找到任何数据源。事实上,我没有将数据源放在 git 远程 application.properties 上,但它仍然在用户 webservice application.properties 中。
我是否必须放置所有属性才能使我的应用程序正确运行?理想情况下,我希望有不可变的参数。也许不是数据库,而是应用程序名称,例如端口等。
我可以访问以下URL来读取远程application.properties: http://localhost:8012/user-ws/default
有什么配置我忘记了吗?
我更换了
spring.config.import=可选:配置服务器:http://localhost:8012
有了这个:
spring.cloud.config.uri=http://localhost:8082