我有这个配置需要用于 Spring Boot 应用程序。
server.port=8085
server.servlet.context-path=/authserver
#data source
spring.jpa.hibernate.ddl-auto=none
spring.datasource.url=<url>
spring.datasource.username=<username>
spring.datasource.password=<password>
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
默认情况下,spring-boot 会选择位于 src/main/resources/ 中的 application.properties 文件
我想更改此路径并将 spring boot 直接引导到不同的 application.properties 文件
我可以使用以下方法实现此目的
java -jar app.jar --spring.config.location=classpath:/another-location.properties
有没有任何替代解决方案可以在不通过命令行传递参数的情况下实现此目的?
我正在用这个
@PropertySource("file:C:\Users\test\.test\test.properties")
@ConfigurationProperties(prefix = "spring")
public class Configuration {
private String ddlAuto;
private String url;
private String username;
private String password;
private String driverClassName;
}
在我的主课上
@SpringBootApplication
@EnableConfigurationProperties(Configuration.class)
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
之后我尝试执行应用程序,注释掉 src/main/resources/ 下 application.properties 中的所有数据源属性
但它一直给我下面提到的错误并且应用程序无法启动
我指的是这个教程:https://www.mkyong.com/spring-boot/spring-boot-configurationproperties-example/ https://www.mkyong.com/spring-boot/spring-boot-configurationproperties-example/
但正如上面提到的,当我启动 Spring Boot 应用程序时,我收到此错误
***************************
APPLICATION FAILED TO START
***************************
Description:
Binding to target org.springframework.boot.context.properties.bind.BindException:
对此有任何帮助将不胜感激