JonathanGiles / TeenyHttpd

TeenyHttpd is a HTTP server written in Java.
MIT License
17 stars 3 forks source link

Teeny Auto configuration #5

Open alex-cova opened 9 months ago

alex-cova commented 9 months ago

Very very basic auto configuration support.

Now TeenyApplication scans for controllers/configurations/resources. (See AutoConfigurationTest)

Auto configuration order:

  1. @Configuration, @Enabled
  2. @Resource
  3. @Path

@Configuration annotation has its own order value

Since the target (for example: AutoConfigurationTest.class) can have endpoints, @Path annotation is not required.

TeenyApplication.start(AutoConfigurationTest.class);

This auto-configures resources, controllers & configurations.

This PR adds the next annotations:

Annotation Target Description
@Inject Field, Method Specifies that the annotated element must be injected
@PostConstruct Method Specifies the annotated method must be called after its holder being initialized
@Resource Method, Type Similar to jakarta.annotation.Resource
@Configuration Type Specifies the annotated type is a configuration
@Enable Type Specified a class that must be treated as a configuration, this annotation is like a switch, target class must not be annotated as @Configuration
@OnApplicationReady Method Specified that the annotated function must be called after the application is started
@ScanPackage Type Specifies which packages should be scanned
@EventListener Method Marks the function as a listener for TeenyHttpd configuration events, like the configuration of a endpoint

Similar to @Import from spring, @Enable allows TeenyHttp to have annotation-toggles, for example:

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Enable(OpenApiConfiguration.class)
public @interface EnableOpenApi {
}

@EnableOpenApi
public class ExampleApplication  {
}
JonathanGiles commented 8 months ago

Let me know what your plans are on this PR.

alex-cova commented 8 months ago

Let me know what your plans are on this PR.

I'll continue working on this feature after TeenyJson gets merged, some parts of autoconfiguration will depend on TeenyJson.

alex-cova commented 7 months ago

Just added very basic openApi support as demonstration of the auto configuration capabilities, many cases are missing like connections to a DB, those kind of configurations must happend just before anything, thoughts?

Screenshot 2024-03-31 at 2 44 24 a m

I'll refactor how the OpenApi is rendered next commit

Update: Way better OpenApi support