Hamurabi Spring Boot Server
Hello Java and game developers and interested others,
at the moment I am learning Java. My colleagues and me are in a bootcamp and have a recap-time this week.
I want to create a game, that runs on a server and maybe later can be attached to Hive. This game is called Hamurabi.
The first part of it is to create a Spring Boot Server, which can handle some data.
So I started from scratch and here is the very first minimal viable product, a server which accepts http-requests:
Setting up Spring Boot, JPA and H2
I configure the server at start.spring.io:
I downloaded the zipfile and opened it in IntelliJ. I added the dependencies for Jackson into pom.xml:
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
I have created the following two files data-sql and schema.sql:
I have adjusted application.properties:
So, after starting HammurabiApplication.java our Spring Database is up and running:
I can log into the SQL-Console via http://8099:h2-console
We find our data, which was automatically created (with the right settings in appliocation.properties) with the following command:
Setting up the data connection between Repository and Service
Now lets bring these repository data data to the service side on REST Spring:
We create the following packages: configuration, controller, dto, entity, repository and services:
In the folder "dto" we create the dataclass "Userlogdto" with the following content:
Please also create a default constructor to avoid the error message:
Ensure that org.chary.dto.Userlogdto has a non-private no-argument constructor.
Now we copy this file and paste it into the "entity" folder. We rename it to "UserlogEntity". We add "@Entity" and "@Table(name="Userlog") before the beginning of the class Userlog. And the @Id has to be set:
Don't forget to set the default Constructor to avoid the error message:
No default constructor for entity:
Now we create the interface "UserlogRepository" in the package "Repository"and we extend it with the class JPARepository<UserlogEntity, String>:
Now we build the Rest-Controller class and add the annotations
@RestController
@CrossOrigin("*")
@RequestMapping("/userlog")
Before we continue in the controller, we create the UserlogService interface. In this we create the method template
public List getAllUserlogs();
Now we add this Interface into the controller:
Now let's create the Interface-implementation in the service package and make it public to Spring by adding the annotation @Service:
Modelmapper
To get the objects, that are in the entity-class into the dto-class, we use modelmapper. Therefore we add it into the pom.xml
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>2.3.5</version>
</dependency>
Then we add the following to the UserlogServiceImpl-class:
We need to make modelmapper public to Spring. For this we create in the configuration package the ModelMapperConfiguration class.
I mixed up account and username. So I refactored it. But now it works:
If you want to see the complete code, click here. There are just some names exchanged.
This is the very early beginning of my project. I hope I get the time and the knowledge to fulfil my dream to create, at least a small, game that uses HIVE to play it.
Regards, Achim
Leave Hamurabi Spring Boot Server to:
Read more #java posts
Best Posts From Achim Mertens
We have not curated any of achimmertens's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From Achim Mertens
- My Diary For Week 27
- My Diary For Week 26
- Mein IAM+PAM System auf dem Raspberry Pi
- My Diary For Week 25
- Wanderung zum Rothen Kreuz in der Eifel - Hiking in the Eifel (Germany)
- My Diary For Week 24
- My Diary For Week 24
- Backup und Restore meines Raspberry Pi mit Openclaw
- Openbao - ein Opensource Schlüsseltresor
- Mythen und Fakten zu Wärmepumpen
- My Diary For Week 22
- Sammelklage gegen Amazon
- My Diary For Week 20
- OpenClaw-, LLM Wiki- und Meilisearch-Erfahrungsbericht
- My Diary For Week 19
- My Diary For Week 17
- My Diary For Week 16
- My Diary For Week 15
- My Diary For Week 15
- Ansibel Schulung März 2026