A brief description for your project:
Project Description:
The framework, named Force, provides a lightweight and modular structure for developing rest services. It includes custom annotations for defining application components such as controllers and services, and an IoC (Inversion of Control) container for managing dependencies.
Key Features:
- Annotation-Based Configuration: Use custom annotations like
@ForceApp
,@Controller
, and@Service
to define application components. - IoC Container: A built-in IoC container for managing service and controller dependencies.
- ORM Support: Easily connect to a MySQL, Postgres database and perform CRUD operations using the
@Entity
annotation. - Web Server Integration: Easily start and configure a web server with customizable server port and context.
- Class Scanning: Automatically scan and register classes with specific annotations within the defined root package.
Technologies Used:
- Java
- Gradle
- Jackson
- MySQL
- Postgres
- JUnit
- Docker
Project Structure:
src/main/java
: Contains the main application code, including the framework core and annotations.src/test/java
: Contains unit tests for the framework components.
Getting Started:
- Clone the repository.
- Build the project using Gradle.
- Run a docker mySQL
docker run -d -ti --name local-mysql-8 -p 3306:3306 -p 33060:33060 -v mysql-data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=tester mysql:8.0
mysql -u root -p
CREATE DATABASE octopus;
USE octopus;
CREATE TABLE product (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
description VARCHAR(255),
price DOUBLE NOT NULL
);
- Run the
Main
class to start the application. Sample Data:
{
"name": "Sample Product",
"description": "This is a sample product description.",
"price": 19.99
}
- Purpose: Used to extract values from the URI and bind them to method parameters.
- Attributes:
value
: The name of the path variable.
- Example:
@Get("/user/{id}") public User getUser(@PathVariable("id") Long userId) { // Method implementation }
- Purpose: Marks a method to handle HTTP PATCH requests.
- Attributes:
value
: The URL pattern to which the method should respond.type
: The content type that the method consumes.httpCode
: The HTTP status code to return.
- Example:
@Patch(value = "/update/{id}", type = "application/json") public ResponseView<Entity> updateEntity(@PathVariable Long id, @Payload Map<String, Object> patchMessage) { // Method implementation }
- Purpose: Maps HTTP GET requests onto specific handler methods.
- Attributes:
value
: The path for the HTTP GET request.type
: The content type of the response.httpCode
: The HTTP status code to return.
- Example:
@Get(value = "/hello", type = "text/plain") public String sayHello() { return "Hello, World!"; }
- Purpose: Specifies the HTTP DELETE method.
- Attributes:
value
: The path to which the method should respond.type
: The content type of the request.httpCode
: The HTTP status code to return.
- Example:
@Delete("/my-resource") public void deleteResource() { // Method implementation }
- Purpose: Specifies the column name in a database that corresponds to the annotated field in an entity class.
- Attributes:
value
: The name of the column.
- Example:
@Table("my_table") public class MyEntity { @Pk private Long id; @Column("name_column") private String name; }
- Purpose: Specifies the primary key column in a database that corresponds to the annotated field in an entity class.
- Attributes:
value
: The name of the primary key column.
- Example:
@Table("my_table") public class MyEntity { @Pk("id_column") private Long id; @Column("name_column") private String name; }
- Purpose: Indicates that an interface is a repository.
- Attributes: None.
- Example:
@Repository public interface MyRepository extends DbCrud<Long, MyEntity> { // Repository implementation }
- Purpose: Specifies the table name in a database that corresponds to the annotated entity class.
- Attributes:
value
: The name of the table.
- Example:
@Table("my_table") public class MyEntity { @Pk private Long id; @Column private String name; }
- Purpose: Marks a method as an exception handler.
- Attributes:
value
: The type of exception that the method handles.
- Example:
@GlobalExceptionHandler public class MyGlobalExceptionHandler { @ExceptionHandler(SomeException.class) public void handleSomeException(SomeException ex) { // Handle the exception } }
- Purpose: Marks a class as a global exception handler.
- Attributes: None.
- Example:
@GlobalExceptionHandler public class MyGlobalExceptionHandler { @ExceptionHandler(SomeException.class) public void handleSomeException(SomeException ex) { // Handle the exception } }
- Purpose: Marks a field as a not null value.
- Attributes:
value
: The validation message.
- Example:
public class User { @NotNull private String name; }
- Purpose: Marks a field as a not empty value.
- Attributes:
value
: The validation message.
- Example:
public class User { @NotEmpty private String name; }
- Purpose: Marks a field as a not blank value.
- Attributes:
value
: The validation message.
- Example:
public class User { @NotBlank private String name; }
- Purpose: Marks a field as a minimum value.
- Attributes:
value
: The minimum value.message
: The validation message.
- Example:
public class User { @Min(value = 18) private int age; }
- Purpose: Marks a field as a maximum value.
- Attributes:
value
: The maximum value.message
: The validation message.
- Example:
public class User { @Max(100) private int age; }
- Purpose: Marks a field as a future date.
- Attributes:
value
: The validation message.allowedTypes
: The allowed types for the field.
- Example:
public class Invoice { @Future private Date dueDate; }
- Purpose: Marks a field as an email address.
- Attributes:
value
: The validation message.
- Example:
public class User { @Email private String email; }
- Purpose: Marks a field as a past date.
- Attributes:
value
: The validation message.allowedTypes
: The allowed types for the field.
- Example:
public class User { @Past private Date birthDate; }