SiGe
SiGe

Reputation: 338

Properly close EntityManager in Spring

I have a REST API with Spring managed EntityManager. When I try to close it with

@Autowired
EntityManager em.

em.close();

I receive IllegalStateException which is normal because the Spring doc. says so.

My question is: which is the correct way to terminate a REST application created with Spring Boot? Should I be 'disturbed' by this exception?

I googled it a lot but didn't find clear information.

EDIT: what is disturbing is the fact, that if I shut down my application (e.g. in Tomcat) I receive the same IllegalStateException.

Upvotes: 0

Views: 889

Answers (1)

Rodolfo Martins
Rodolfo Martins

Reputation: 131

You don't need to close the EntityManager connection. It will be managed by Spring. So you need to remove the line:

em.close()

Upvotes: 2

Related Questions