我正在尝试在Spring启动和Spring云上构建一个示例应用程序。我已经在config.properties属性文件中编写了我的数据库和hibernate配置,该文件位于我的桌面中,我希望我的spring boot能够使用这个配置。
我的项目有3个模块
这是我在API的application.property文件中提到的代码
spring.profiles.active = native spring.cloud.config.server.native.searchLocation = C:/Users/DEV/Desktop/configuration/config.properties
并且数据层和服务层的属性文件为空
但是当我运行API时,我收到以下错误
***************************
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).
Process finished with exit code 1
任何人都可以帮我解决这个错误。
提前致谢。
这不是从您的API模块完成的。您将配置服务器属性添加到“客户端”(从配置的角度来看)应用程序。
如果您想使用Spring Cloud Config配置项目,您应该有单独的应用程序来管理您的配置。我们称之为config-server
。 (您应该正确配置maven或gradle依赖项,请参阅文档)要在native
的config-server
中配置application.properties
配置文件的使用,您必须添加问题中提到的属性(native
配置文件的示例)。
spring.profiles.active=native
spring.cloud.config.server.native.searchLocation=file:<path-to-the-directory-with-conf-files> or classpath:/<path-to-the-directory-with-conf-files>
注意:config-server
可以处理许多服务的配置。更多信息可以在文档Spring Cloud Config Server section中找到。
然后在您的API(或任何其他模块)中,这是一个Spring启动应用程序,您应该添加spring-cloud-config-client
依赖项并添加bootstrap.properties
(或.yml)配置文件。你应该添加描述与config-server
通信的属性。默认情况下,config-server
侦听端口8888。
spring.application.name=<your app name>
spring.cloud.config.uri=http://localhost:8888 # this is also default value for this property
在启动时,它将通过http发送到config-server
并根据服务名称(spring.application.name
)获取配置属性。更多信息可以在Spring Cloud Config client section找到
重要提示:确保在配置目录中正确组织文件(由native
使用的config-server
配置文件),找到一些示例。属性文件命名很重要。首先,您可以尝试使用your-application-name.properties
您必须有文件:前缀到属性文件位置。
来自https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_server.html的文档
Config Server中还有一个“本机”配置文件,它不使用Git,但从本地类路径或文件系统加载配置文件(使用spring.cloud.config.server.native.searchLocations指向任何静态URL) )。要使用本机配置文件,请使用spring.profiles.active = native启动配置服务器。