此内容没有您所选择的语言版本。
Chapter 5. Contexts and Dependency Injection (CDI) in Camel Quarkus
CDI plays a central role in Quarkus and Camel Quarkus offers a first class support for it too.
You may use @Inject, @ConfigProperty and similar annotations e.g. to inject beans and configuration values to your Camel RouteBuilder, for example:
- 1
- The
@ApplicationScopedannotation is required for@Injectand@ConfigPropertyto work in aRouteBuilder. Note that the@ApplicationScopedbeans are managed by the CDI container and their life cycle is thus a bit more complex than the one of the plainRouteBuilder. In other words, using@ApplicationScopedinRouteBuildercomes with some boot time penalty and you should therefore only annotate yourRouteBuilderwith@ApplicationScopedwhen you really need it. - 2
- The value for the
timer.periodproperty is defined insrc/main/resources/application.propertiesof the example project.
Please refer to the Quarkus Dependency Injection guide for more details.
5.1. Accessing CamelContext 复制链接链接已复制到粘贴板!
To access CamelContext just inject it into your bean:
5.2. CDI and the Camel Bean component 复制链接链接已复制到粘贴板!
5.2.1. Refer to a bean by name 复制链接链接已复制到粘贴板!
To refer to a bean in a route definition by name, just annotate the bean with @Named("myNamedBean") and @ApplicationScoped. The @RegisterForReflection annotation is important for the native mode.
Then you can use the myNamedBean name in a route definition: