我有一個特殊的性能測試資源目錄中的文件爲什麼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