gpt4 book ai didi

java - CamelContext camelContext = SpringCamelContext.springCamelContext(appContext, false);在 Camel 版本 2.17.3 中弃用

转载 作者:行者123 更新时间:2023-12-01 04:01:25 24 4
gpt4 key购买 nike

我正在使用 Spring + Apache Camel 示例。在前面的示例中,我使用的是 camel-core version 2.15.1。现在我刚刚将依赖项更新为 2.17.3 当我更新依赖项时,我发现下面的方法已被弃用:

CamelContext camelContext = SpringCamelContext.springCamelContext(appContext, false);

那个的替换代码是什么?

请引用下面我的代码:CamelTimerFeedingActiveMqExample

public class CamelTimerFeedingActiveMqExample {
public static final void main(String[] args) throws Exception {
ApplicationContext appContext = new ClassPathXmlApplicationContext("timerFeedActiveMqApplicationContext.xml");
CamelContext camelContext = SpringCamelContext.springCamelContext(appContext, false);
try {
camelContext.start();
Thread.sleep(5000);
} finally {
camelContext.stop();
}
}
}

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false" />
</bean>

<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="connectionFactory" ref="connectionFactory" />
</bean>

<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="activemq:queue:numbers" />
<to uri="log:com.javarticles?level=INFO&amp;groupInterval=10000" />
</route>
</camelContext>
</beans>

timerFeedActiveMqApplicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false" />
</bean>

<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="connectionFactory" ref="connectionFactory" />
</bean>

<camelContext xmlns="http://camel.apache.org/schema/spring">
<route id="timerPingToInQueue">
<from uri="timer:ping?period=1s" />
<transform>
<simple>Ping at ${date:now:yyyy-MM-dd HH:mm:ss}</simple>
</transform>
<to uri="activemq:queue:ping_queue" />
</route>
<route id="InQueueToConsole">
<from uri="activemq:queue:ping_queue" />
<to uri="stream:out" />
</route>
</camelContext>
</beans>

timerSelectQueryApplicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">

<context:property-placeholder location="classpath:database.properties"/>

<bean id="orderProcessor" class="com.javarticles.camel.components.OrderProcessor"/>

<jdbc:initialize-database data-source="dataSource" enabled="true">
<jdbc:script location="classpath:db-schema.sql" />
<jdbc:script location="classpath:db-test-data.sql" />
</jdbc:initialize-database>


<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${mysql.driver.class.name}" />
<property name="url" value="${mysql.url}" />
<property name="username" value="${mysql.username}" />
<property name="password" value="${mysql.username}" />
</bean>

<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="timer://queryTimer?period=2s" />
<setBody>
<constant>
SELECT * FROM ORDERS WHERE STATUS='NEW' ORDER BY NAME
</constant>
</setBody>
<to uri="jdbc:dataSource" />
<split>
<simple>${body}</simple>
<to uri="bean:orderProcessor" />
</split>
</route>
</camelContext>
</beans>

pom.xml

<properties>
<!-- General Properties -->
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<!-- Apache Camel -->
<apache.camel.version>2.17.3</apache.camel.version>

<!-- Spring Framework -->
<spring.version>4.3.1.RELEASE</spring.version>

<!-- MYSQL -->
<mysql.version>5.1.39</mysql.version>

<!-- Logging Framework -->
<logback.version>1.1.7</logback.version>
<jcl-over-slf4j.version>1.7.21</jcl-over-slf4j.version>

<!-- Junit Framework -->
<junit.version>4.12</junit.version>
</properties>


<dependencies>
<!-- Spring Context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>

<!-- Spring JDBC -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Camel core -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${apache.camel.version}</version>
</dependency>

<!-- camel stream -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-stream</artifactId>
<version>${apache.camel.version}</version>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jms</artifactId>
<version>${apache.camel.version}</version>
</dependency>

<!-- camel spring -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring</artifactId>
<version>${apache.camel.version}</version>
</dependency>

<!-- camel JDBC -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jdbc</artifactId>
<version>${apache.camel.version}</version>
</dependency>

<!-- MYSQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>

<!-- JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

图片: enter image description here

最佳答案

您只需要在下面使用。完成!

public class CamelTimerSqlQueryExample {
public static final void main(String[] args) throws Exception {
ApplicationContext appContext = new ClassPathXmlApplicationContext("timerSelectQueryApplicationContext.xml");
CamelContext camelContext = new SpringCamelContext(appContext) ;
try {
camelContext.start();
Thread.sleep(5000);
} finally {
camelContext.stop();
}
}
}

关于java - CamelContext camelContext = SpringCamelContext.springCamelContext(appContext, false);在 Camel 版本 2.17.3 中弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39298401/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com