Tag Archives: Unable to acquire JDBC Connection

Spring @Async interrupt/Unable to acquire JDBC Connection

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