January 2018
Intermediate to advanced
348 pages
8h 17m
English
Our service needs to interact with a database for working with the entities. As an example, we have set up H2 as an in-memory database for our microservices. We need to have a datasource configured, which will be used by JPA. This can be done by using the <datasource> tag in the web.xml file:
<data-source> <name>java:global/datasource</name> <class-name>org.h2.jdbcx.JdbcDataSource</class-name> <url>jdbc:h2:mem:users;DB_CLOSE_DELAY=-1</url></data-source>
The <url> value defines the H2 in-memory database called users, and the DB_CLOSE_DELAY flag is used to ensure the database is retained in memory, even if connections are closed to it.
Then the datasource/name is referred to in src/main/resources/META-INF/persistence.xml ...
Read now
Unlock full access