When writing code today, you need to add @ async asynchronous processing to a certain method, which involves database operation, that is, using DAO method call
So I wrote a unit test method to test the asynchronous method
It turned out that the report was wrong
interrupt/Unable to acquire JDBC Connection
It was when Dao was called that it exploded wrong. Strange, how can not get the connection
Before, when starting the whole project and running, the @ async asynchronous method execution can be executed
For a moment, I tried to start the project to test. Sure enough, there is no problem
Conclusion
This is the problem of unit testing
Because @ async is executed after the unit test method is executed. At this point, the unit testing framework and spring think that the unit testing has been successful
Then the connection is closed and a column is processed to end the processing of the application. Therefore, when executing asynchrony at this time, the database connection cannot be obtained
Similar Posts:
- WebSocket Error: Unable to unwrap data, invalid status [CLOSED]
- Unit test reports an error nosuchbeandefinitionexception
- When spring boottest performs unit testing, the injection object reports an error and cannot be tested
- SpringBoot Frame: Failed to determine a suitable driver class [How to Solve]
- Failed to parse source for import analysis because the content contains invalid JS syntax
- Failed to resolve: junit:junit:4.12 [How to Solve]
- Data truncation: Data too long for column ‘****’
- How to deal with the exception of database connection pool in Python flash
- Error in service Metasploit start in Kali
- [Solved] Cannot resolve symbol ‘SpringJUnit4ClassRunner’