This project include dependencie injection and controllers annotations that consume a servlet
<dependencies>
<dependency>
<groupId>io.github.cscristianmoreno</groupId>
<artifactId>web</artifactId>
<version>1.0</version>
</dependency>
</dependencies>/** Annotation to launch tomcat server */
@Server
public class App {
public static void main(String[] args) throws Exception {
/** Initialized the IoC */
IOCInitializer.main(args);
}
}The implementation ServletContainerInitializer is the one in charge onStartup method.
This interface:
@HandlesTypes(Controller.class)load all classes that matches with @Controller annotation, next, i use a Java Reflection to access a class property.
For default package scan is com/../.. If you wish change to another package name, you need use
PackageScanUtil.setScan("org");
IOCInitializer.main(args);@Controller("/users")
public class UserController {
@GET("/value/{id}/test/{name}")
private String message(@Variable int id, @Variable String name) {
return "Hi! " + name + " " + "#" + Integer.toString(id)
}
@POST("/save")
public Users save(@Body Users users) {
return users;
}
}@Component
public class MyComponent {
public String getMessage() {
return "MyComponent has been returned this message";
}
}@Injectable
public class MyInjectable {
@Inject
private MyComponent myComponent;
public String getMessage() {
return myComponent.getMessage();
}
}Or else
@Component
public class SimpleComponent {
private final MyComponent myInjectable;
@Constructor
public UserController(final MyInjectable myInjectable) {
this.myInjectable = myInjectable;
}
...
}- @GET("/../{...}/.../{...}")
- @POST("/../{...}/.../{...}")
- @PUT("/../{...}/.../{...}")
- @PATCH("/../{...}/.../{...}")
- @DELETE("/../{...}/.../{...}")
- @Body
- @Variable
- @Param(..)
- @Header(..)
Create a new class instance.
The classes with this annotation can use @Inject in field or constructor
This annotation is required for use in @Inject fields.
* Can inject dependencie
Get a instance to @Injectable class.
This annotation required @Component or @Injectable in the same class to can use.
@Inject -> (@Component | @Injectable)
Create a new classe instance.
This annotation is required to inject dependencie
* Can inject dependencie
A semanthic annotation to indicate that fields will injected through constructor
This annotation run Apache Tomcat