...
Else, if more customisation is needed, any CamelContext
class can be used to declare a custom Camel context bean. Then, the @PostConstruct
and @PreDestroy
lifecycle callbacks can be done to do the customisation, e.g.:
Code Block | ||
---|---|---|
| ||
@ApplicationScoped class CustomCamelContext extends DefaultCamelContext { @PostConstruct void customize() { // Set the Camel context name setName("custom"); // Disable JMX disableJMX(); } @PreDestroy void cleanUp() { // ... } } |
...
Code Block | ||
---|---|---|
| ||
@ApplicationScoped class ManualStartupCamelContext extends DefaultCamelContext { @PostConstruct void manual() { @PostConstruct void manual() { setAutoStartup(false); } } |
Multiple Camel contexts support
Configuration properties
To configure the sourcing of the configuration properties used by Camel to resolve properties placeholders, you can declare a PropertiesComponent
bean qualified with @Named("properties")
, e.g.:
Code Block | ||
---|---|---|
| ||
@Produces
@ApplicationScoped
@Named("properties")
PropertiesComponent propertiesComponent() {
Properties properties = new Properties();
properties.put("property", "value");
PropertiesComponent component = new PropertiesComponent();
component.setInitialProperties(properties);
component.setLocation("classpath:placeholder.properties");
return component;
} |
If you want to use DeltaSpike configuration mechanism you can declare the following PropertiesComponent
bean:
Code Block | ||
---|---|---|
| ||
@Produces @ApplicationScoped @Named("properties") PropertiesComponent properties(PropertiesParser parser) { PropertiesComponent component = new PropertiesComponent(); component.setPropertiesParser(parser); return component; } // PropertiesParser bean that uses DeltaSpike to resolve properties static class DeltaSpikeParser extends DefaultPropertiesParser { @Override public String parseProperty(String key, String value, Properties properties) { return setAutoStartupConfigResolver.getPropertyValue(falsekey); } } |
Multiple Camel contexts support
Configuration properties
camel-example-cdi-properties
example for a working example of a Camel CDI application using DeltaSpike configuration mechanism.Auto-configured type converters
...
Code Block | ||
---|---|---|
| ||
class MyBean { //... } from("direct:inbound").bean(MyBean.class); |
Or to lookup a CDI bean by name from the Java DSL:
Code Block | ||
---|---|---|
| ||
@Named("foo") class MyBean { //... } from("direct:inbound").bean("foo"); |
...