https://github.com/vmj/cdi-se-example
Example Java SE + CDI 2.0 applications
https://github.com/vmj/cdi-se-example
cdi dependency-injection java java-8 java-9 java-se java8 java9 javase
Last synced: 7 months ago
JSON representation
Example Java SE + CDI 2.0 applications
- Host: GitHub
- URL: https://github.com/vmj/cdi-se-example
- Owner: vmj
- Created: 2016-09-09T22:33:34.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2021-01-08T20:41:28.000Z (almost 5 years ago)
- Last Synced: 2025-02-03T22:40:52.045Z (9 months ago)
- Topics: cdi, dependency-injection, java, java-8, java-9, java-se, java8, java9, javase
- Language: Java
- Homepage:
- Size: 189 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.adoc
Awesome Lists containing this project
README
image:https://travis-ci.org/vmj/cdi-se-example.svg?branch=master["Build Status", link="https://travis-ci.org/vmj/cdi-se-example"]
# Example Java SE + CDI 2.0 applications
This repository contains one application based on *OpenWebBeans*, and another based on *Weld SE*.
Those are CDI containers (think dependency injection) readily usable in a Java SE environment.
For example, small apps or 12 factor apps.## Why and What?
Think what you will about the enterprise Java as a whole, some of their technologies are really neat.
Also, since they are more and more usable without any heavy frameworks or boilerplate or configuration,
they are a real contender in Java SE space.Dependency injection allows you to decouple the components of your app,
so you don't need to spend any time thinking about constructing and wiring them up.
CDI also takes care of lifecycle management of those components,
so you get safe singletons without even thinking about multi-threading issues.
CDI even has a neat event system.
All this with next to no annotations or configuration.## How it works
This project contains a `bean-archive`, which is just a JAR really,
that contains CDI compatible beans, which are just POJOs really.
This JAR forms the actual application.
There's an `App` class that listens to a CDI event to start whatever the app does,
and a `Boot` class that contains the standard Java `main` function.Then there are two Java applications: `owb-app` and `weld-app`.
Both are really small.
They don't even contain any code;
just a build file that instructs the build tool to compose a Java application.Both applications use the `Boot` class from the `bean-archive` to bootstrap the application.
All it does is, it uses CDI 2.0 way of constructing the CDI container and then fires the
CDI event expected by the `App` class.That's it. (See the source code for more comments.)
## How to try it out
I'm using *gradle* build system, but you do not need to install that in order to build this.
All you need is *Java SE JDK*, version 8 or newer. (Java 8 requirement is in CDI spec; tested with JDK 15)Clone this repository:
git clone https://github.com/vmj/cdi-se-example.git
cd cdi-se-exampleThen run the OpenWebBeans based app:
./gradlew owb-app:run
And the Weld based app:
./gradlew weld-app:run
If you're on Windows, use the `gradlew.bat` script instead of `./gradlew`.
You can clean up, too
./gradlew clean
Have fun! (And see a bit more interesting example: https://github.com/vmj/swing-cdi-example)