我有一个特殊的性能测试资源目录中的文件为什么spring boot首先在测试资源中不使用application.properties?
└── test
├── java
│ └── com
│ └── inter3i
│ ├── dao
│ │ └── FooMapperTest.java
└── resources
└── application.properties
在此
的application.properties文件我指定的MySQL URL。
spring.datasource.url=jdbc:mysql://139.224.xxx.xxx/foo?useSSL=false
然后我执行测试
mvn test -Dtest=com.foo.reportapi.dao.FooMapperTest
但失败了,因为
org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:289) ~[spring-jdbc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
但实际上MySQL的URK是确定的,为什么它有这样的错误?从Wireshark的我知道它实际连接到另一个URL
spring.datasource.url=jdbc:mysql://192.168.0.25/foo
这application-default.properties
src
├── main
│ └── resources
│ ├── application-default.properties
配置那么,为什么会这样有悖常理?我认为测试类首先应该在测试资源中使用application.properties
。
此外,我必须使用wireshark来查找它连接到哪个URL,我怎么能得到Spring Boot明确输出MySQL URL信息?
每https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html'应用程序 - {profile}'比'application'具有更高的优先级。 – jonrsharpe