Skip to content

Teeny Auto configuration#5

Open
alex-cova wants to merge 23 commits intoJonathanGiles:masterfrom
alex-cova:TeenyAutoconfiguration
Open

Teeny Auto configuration#5
alex-cova wants to merge 23 commits intoJonathanGiles:masterfrom
alex-cova:TeenyAutoconfiguration

Conversation

@alex-cova
Copy link
Copy Markdown
Collaborator

@alex-cova alex-cova commented Feb 21, 2024

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  {
}

Copy link
Copy Markdown
Owner

@JonathanGiles JonathanGiles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just one minor comment. We need to improve JavaDoc and readme at some point too!

Comment thread http/Client.http Outdated

###

http://localhost:80/todos/todos No newline at end of file
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

presumably it can be deleted...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this?

Client.http is a client from IntelliJ, I forgot to remove it :S

@JonathanGiles
Copy link
Copy Markdown
Owner

Let me know what your plans are on this PR.

@alex-cova
Copy link
Copy Markdown
Collaborator Author

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
Copy link
Copy Markdown
Collaborator Author

alex-cova commented Mar 31, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants