A Spring Boot 3.4 application for managing employee data with a Vaadin-based web UI was generated by Junie to examine the power of AI in generating code. Read the article to learn more.
Article: Can Junie be a real competitor for Cursor, Windsurf, and VS Code Copilot?.
employee-service/
├── frontend/ # Frontend resources for Vaadin
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── saeed/
│ │ │ ├── controller/
│ │ │ │ └── EmployeeController.java
│ │ │ ├── model/
│ │ │ │ └── Employee.java
│ │ │ ├── repository/
│ │ │ │ ├── EmployeeRepository.java
│ │ │ │ └── JdbcEmployeeRepository.java
│ │ │ ├── service/
│ │ │ │ └── EmployeeService.java
│ │ │ ├── ui/
│ │ │ │ ├── EmployeeForm.java
│ │ │ │ ├── EmployeeListView.java
│ │ │ │ └── MainLayout.java
│ │ │ └── Main.java
│ │ └── resources/
│ │ ├── META-INF/resources/themes/
│ │ │ └── employee-management/
│ │ │ ├── styles.css
│ │ │ └── theme.json
│ │ ├── application.properties
│ │ └── schema.sql
│ └── test/
│ └── java/
│ └── com/
│ └── saeed/
│ ├── controller/
│ │ └── EmployeeControllerTest.java
│ ├── repository/
│ │ └── JdbcEmployeeRepositoryTest.java
│ └── service/
│ └── EmployeeServiceTest.java
├── docker-compose.yml
├── package.json # Frontend dependencies
├── pom.xml # Backend dependencies
├── tsconfig.json # TypeScript configuration
├── vite.config.ts # Vite build configuration
└── other frontend configuration files
- Spring Boot 3.4.0
- Java 17
- Maven
- PostgreSQL 16 (in Docker setup)
- Docker and Docker Compose (for containerized database)
- Spring Boot Docker Compose (for automatic Docker Compose integration)
- Vaadin Flow 24.3.5/24.3.6 (for the web UI)
- TypeScript
- Vite (frontend build tool)
- Testcontainers 1.19.7 (for integration testing)
- Java 17 or higher
- Maven 3.6 or higher
- Node.js and npm (for frontend development)
- Docker and Docker Compose (recommended for the database setup)
- PostgreSQL 16 (if not using Docker)
The project uses Spring Boot Docker Compose to automatically integrate with Docker Compose:
- Make sure Docker and Docker Compose are installed on your system
- Run the following command in the project root directory:
docker-compose up -d
-
This will start a PostgreSQL container with the following configuration:
- Database: employee_db
- Username: postgres
- Password: postgres
- Port: 5432
-
When you start the application, Spring Boot Docker Compose will automatically:
- Detect the running Docker Compose services
- Configure the database connection properties
- Connect to the PostgreSQL container
-
The application will automatically create the tables and insert initial data when it starts.
If you prefer to use an existing PostgreSQL installation:
-
Install PostgreSQL if not already installed:
- Ubuntu/Debian:
sudo apt-get install postgresql postgresql-contrib
- macOS:
brew install postgresql
- Windows: Download and install from PostgreSQL website
- Ubuntu/Debian:
-
Start the PostgreSQL service:
- Ubuntu/Debian:
sudo service postgresql start
- macOS:
brew services start postgresql
- Windows: PostgreSQL is installed as a service and should start automatically
- Ubuntu/Debian:
-
Create the database:
sudo -u postgres psql CREATE DATABASE employee_db; \q
-
The application will automatically create the tables and insert initial data when it starts.
-
Configure the application (if needed):
- The default configuration assumes PostgreSQL is running on localhost:5432 with username 'postgres' and password 'postgres'
- If your setup is different, update the
src/main/resources/application.properties
file:spring.datasource.url=jdbc:postgresql://localhost:5432/employee_db spring.datasource.username=postgres spring.datasource.password=postgres
mvn clean install
mvn spring-boot:run
Or after building:
java -jar target/employee-service-0.0.1-SNAPSHOT.jar
After starting the application, you can verify that it's correctly connected to the PostgreSQL database:
-
Check the application logs for successful database initialization:
INFO ... - Executing SQL script from class path resource [schema.sql]
-
Make a request to the API to retrieve employees:
curl -X GET http://localhost:8080/api/employees
You should see the initial data that was inserted by schema.sql.
-
If you want to directly check the database:
# For local PostgreSQL psql -U postgres -d employee_db -c "SELECT * FROM employees;" # For Docker PostgreSQL docker exec -it employee-postgres psql -U postgres -d employee_db -c "SELECT * FROM employees;"
The application provides a web-based user interface built with Vaadin Flow. The UI allows you to:
- View a list of all employees
- Filter employees by name, email, or department
- Add new employees
- Edit existing employees
- Delete employees
To run the application with the Vaadin UI:
- Make sure the database is set up (see Database Setup section above)
- Build the application:
mvn clean install
- Run the application:
mvn spring-boot:run
- Wait for the application to start completely. You should see a message like:
Employee Service Application with Vaadin UI Started!
- The first startup might take longer as Vaadin compiles the frontend resources
Once the application is running, you can access the UI by opening a web browser and navigating to:
http://localhost:8080
- Employee List: The main view displays a grid of all employees with their details.
- Filtering: Use the search field to filter employees by any field.
- Add Employee: Click the "Add Employee" button to create a new employee.
- Edit Employee: Click on an employee in the grid to edit their details.
- Delete Employee: When editing an employee, you can delete them using the Delete button.
If you encounter issues with the Vaadin UI:
- UI not loading: Make sure the application is fully started. Check the console logs for any errors.
- Blank page: Try clearing your browser cache or opening in a private/incognito window.
- Frontend compilation errors: Delete the
node_modules
directory and thepackage-lock.json
file, then restart the application. - Database connection issues: Ensure your PostgreSQL database is running and accessible.
- Development mode: For faster development iterations, use:
mvn spring-boot:run -Pproduction
The application also provides a RESTful API for programmatic access:
GET /api/employees
- Get all employeesGET /api/employees/{id}
- Get employee by IDPOST /api/employees
- Create a new employeePUT /api/employees/{id}
- Update an existing employeeDELETE /api/employees/{id}
- Delete an employee
curl -X GET http://localhost:8080/api/employees
curl -X GET http://localhost:8080/api/employees/1
curl -X POST http://localhost:8080/api/employees \
-H "Content-Type: application/json" \
-d '{"firstName":"Alice","lastName":"Johnson","email":"alice.johnson@example.com","department":"Marketing"}'
curl -X PUT http://localhost:8080/api/employees/1 \
-H "Content-Type: application/json" \
-d '{"firstName":"John","lastName":"Smith","email":"john.smith@example.com","department":"Sales"}'
curl -X DELETE http://localhost:8080/api/employees/1