0

I'm new to apache camel. I was trying to understand the use of Integrating Spring framework with Apache Camel. I am not comparing Spring vs Apache camel here. I am trying to understand if Dependency Injection is the only use of integrating Spring with camel for a Java Project. Since Camel can take care of a lot of things like routing and also JDBC config that even spring framework can do. In my project we are using Google juice for DI instead of spring. I know that there are other modules like spring security, AOP that could be utilized from spring. But don't you think we can achieve the same using other libraries. So what am i missing here? Is my understanding correct? What are the other uses of integrating spring with apache camel when we can achieve the same DI using google guice and camel.

1 Answer 1

1

if your project camel has spring, you can use all features of spring framework, for example if you need Spring JDBC you can declare that dependency and use it in camel. I will give you an example:

In your pom.xml

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <scope>provided</scope>
</dependency>    

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <scope>provided</scope>
</dependency>

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <scope>provided</scope>
</dependency>

In your camel-context.xml

<!-- Datasource -->
<bean class="org.springframework.jdbc.datasource.SimpleDriverDataSource"
    id="dataSource">
    <property name="driverClass" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
    <property name="url"
        value="${ds.urlString}://${ds.server}:${ds.port};databaseName=${ds.bd}" />
    <property name="username" value="${ds.user}" />
    <property name="password" value="${ds.password}" />
</bean>

<!-- processors -->
<bean
    class="com.mycomapny.Processor"
    id="idProcessor" />

As you can see in the example you are injecting dependency, and you can use it in a dao class.

regards

Sign up to request clarification or add additional context in comments.

2 Comments

Yep. Correct. But the same injecting dependency can be done using apache guice and in config right? Something like the below: ` DataSource ds = bootStrapDataSource(bootMode.getConfigSuffix(), configService, ReadOnlyDB.myDB); main.bind("mymodule", ds); ` and calling it using apache camel as **` .to("jdbc:mymodule") `. So is DI the only use of integrating Spring with Apache camel?
really not used apache guice, but it will depend on what you require in your project, I could use blueprint instead of spring, but personally I like the spring JDBC feature because you have more control.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.