"I want to understand the insides of frameworks like Spring and Struts."
"But it's so big, I don't know where to start."
This is perfect for such people.Creating a simple framework in Javais.
Dependency injection, routing, annotation processing, etc.Basic Concept of the FrameworkBy making it with your own hands,
This course will dramatically deepen your understanding of the design skills and mechanisms required in the workplace.
In this article, we will introduce how to build a system that even beginners to intermediate users can use.How to create a super simple Java frameworkof,
Code examples, diagrams, and solutions to common stumbling pointsI will explain in detail with.
- What is a framework?
- Designing the minimum framework configuration
- Annotation definition: Controller.java
- Example of user code implementation: SampleApp.java
- Framework body: MiniFramework.java
- Executable file: Main.java
- Common errors and how to fix them
- Learn more with advanced features
- Final summary and composition
- Summary: The quickest route to understanding Java
What is a framework?
The importance of the mechanism can only be understood by making it yourself
Conclusion: A framework is a toolbox that standardizes frequently used mechanisms.
Famous frameworks like Spring and Laravel
It is basically a set of "rules, parts, and flow."
By creating your own mini-framework, you gain the following capabilities:
- How to use annotations
- The concept of DI (Dependency Injection)
- Routing Structure
- Ingenuity to automate the process
Designing the minimum framework configuration
All the features you need
Conclusion: You can create a "really good framework" with just these three features:
- Routing Process(Calling a function from a string)
- DI function(Automatically pass objects)
- Annotation analysis(Marking class methods)
Java configuration image:
1 |
|
Annotation definition: Controller.java
1 |
|
Example of user code implementation: SampleApp.java
1 |
)
); } } |
Framework body: MiniFramework.java
1 |
);
|
Executable file: Main.java
1 |
}, ); } } |
Common errors and how to fix them
Here are some common stumbling points and how to deal with them
- Annotations are ignored
@Retention(RetentionPolicy.RUNTIME)
If you forget, it won't be recognized at run time.- Error in newInstance()
- If there is no default constructor, an error will occur. Be sure to provide a no-argument constructor.
- The method is not called
invoke()
throws an exception,try-catch
Let's surround it with .
Learn more with advanced features
Improve your skills with advanced examples
@Route(method="GET", path="/user")
Add annotations like- Change to a structure that receives parameters
- The ability to load routes from files or configuration classes
Final summary and composition
- MiniFramework.java: Routing and DI implementation
- Controller.java: annotation definition
- SampleApp.java:User code
- Main.java: Startup class
Summary: The quickest route to understanding Java
In this article,How to create your own framework in JavaWe introduced the following.
What I learned:
- Defining and Using Annotations
- Routing structure using reflection
- A small way to learn big ideas
Why are frameworks useful?To realize this,
The best way to learn is to try making it yourself at least once.
We hope you will use this article as an opportunity to venture into the world of self-made frameworks!