Java Magazine, Jan/Feb 2016
ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2016 83 microservices executions plugin This is the bare minimum required to run a microservice with plain servlets and static files To try it out we can add a simple index xhtml HTML file KumuluzEE will use the webapp folder at the root of the resource folder to look for configuration data and files This is where we should put the files To try it out run maven package Then you can start the microservice using the following command java cp ui target classes ui target dependency com kumuluz ee EeApplication Go to http localhost 8080 in your browser and you should see the content of the index xhtml HTML file Of course you can use JSP use a servlet or add JSF support and use it for the front end We will extend the front end shortly Defining the JPA Module We follow the procedure described above for each microservice Because each microservice is its own project you can customize it as much as you need Before we start developing the routes and booking services we will define the JPA module with entities To include JPA we add the EclipseLink JPA implementation We will also add the database driver In our case we will use the PostgreSQL database However you are free to use any database Place the required dependencies in models pom xml dependency groupId com kumuluz ee groupId artifactId kumuluzee jpa eclipselink artifactId version kumuluzee version version dependency dependency groupId org postgresql groupId artifactId postgresql artifactId version 94 1201 jdbc41 version dependency Next we will add the persistence xml file and entity classes that will be shared with both our microservices even though the microservices will be run separately This file is the same as what you would develop in a traditional Java EE application You can look at the provided sample source code to see an example Notice that the values defined in persistence xml for the database URL username and password can be overwritten by setting the DATABASE_ URL DATABASE_ USER and DATABASE_ PASS environment variables respectively Doing this is useful for easy configuration in Docker style environments We are now ready to write the entity classes We use standard JPA which does not require any modifications for KumuluzEE The example JPA entity classes for Route and Booking are shown next The first file models Route java contains the following @ Entity @ NamedQuery name Route findAll query SELECT r FROM Route r public class Route @ Id @ GeneratedValue strategy GenerationType IDENTITY private Integer id private String name private String start private String end
You must have JavaScript enabled to view digital editions.