Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 我需要转义application.properties中的特殊字符吗?_Spring_Spring Boot_Application.properties - Fatal编程技术网

Spring 我需要转义application.properties中的特殊字符吗?

Spring 我需要转义application.properties中的特殊字符吗?,spring,spring-boot,application.properties,Spring,Spring Boot,Application.properties,在数据源密码字段中有特殊字符,如“(双引号)、@、~、!、%、&、}、]等。当我运行springboot应用程序时,以及当它尝试连接到我运行的数据库时- com.microsoft.sqlserver.jdbc.SQLServerException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: &quo

在数据源密码字段中有特殊字符,如“(双引号)、@、~、!、%、&、}、]等。当我运行springboot应用程序时,以及当它尝试连接到我运行的数据库时-

com.microsoft.sqlserver.jdbc.SQLServerException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "problem accessing trust store"
Caused by: java.security.KeyStoreException: problem accessing trust store
Caused by: java.io.IOException: Keystore was tampered with, or password was incorrect
Caused by: java.security.UnrecoverableKeyException: Password verification failed
我的问题是:
(1) 有没有办法查看Spring尝试连接时使用的密码?
(2) 是否需要在
应用程序.properties
中转义密码中的任何特殊字符

我可以使用一个独立的java程序连接到数据库,但我不得不避开密码中的双引号。我在后端使用Springboot-2.0.4、Flyway-5.2.4、jdk 1.8和MS-SQL server


谢谢。

应用程序。属性:指定的字符不需要转义

application.yml:用
包围值,并像这样转义嵌入的

注意:application.yml不属于OP的问题。请使用application.propertiesapplication.yml,而不要同时使用两者

使用application.properties中的此条目进行测试和验证

并在application.yml中使用此条目再次测试

输出值到控制台,如下所示(将代码放入其中,例如用
@springbootplication
注释的类,将在应用程序启动时运行)

用Flyway,试试这个

/**
 * Override default flyway initializer to do nothing
 */
@Bean
FlywayMigrationInitializer flywayInitializer(Flyway flyway, @Value("${myapp.entry-with-special-characters}") String myVal) {
    System.out.printf("Test-output for StackOverflow: %s\n", myVal);
    return new FlywayMigrationInitializer(flyway, (f) ->{} );
}

问题的答案

有没有办法查看Spring在尝试 联系

可以使用application.properties中的相关键替换上述bean中具有特殊字符的键
myapp.entry。请记住,密码是秘密

测试期间使用的环境:

  • 弹簧靴2.4.1
  • JDK14.0.2
  • Windows 10主页
myapp:
  entry-with-special-characters: "@~!%&=\"\""
@Bean
public CommandLineRunner propertiesTest(@Value("${myapp.entry-with-special-characters}") String myVal) {
    return args -> System.out.printf("Test-output for StackOverflow: %s\n", myVal);
}
/**
 * Override default flyway initializer to do nothing
 */
@Bean
FlywayMigrationInitializer flywayInitializer(Flyway flyway, @Value("${myapp.entry-with-special-characters}") String myVal) {
    System.out.printf("Test-output for StackOverflow: %s\n", myVal);
    return new FlywayMigrationInitializer(flyway, (f) ->{} );
}