当前位置: 首页 > 知识库问答 >
问题:

Spring Boot Camel JPA没有要加入的本地事务

施喜
2023-03-14

我在用

Spring Boot 1.5.10.RELEASE
Camel 2.21.1
Java 1.8

我的申请

@SpringBootApplication
@ImportResource({"classpath:my-webservice.xml", "classpath:my-camel.xml"})
public class CamelCXFApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(CamelCXFApplication.class, args);
    }

    @Bean
    ServletRegistrationBean servletRegistrationBean() {
        ServletRegistrationBean servlet = new ServletRegistrationBean(new CamelHttpTransportServlet(), "/camel-rest-jpa/*");
        servlet.setName("CamelServlet");
        return servlet;
    }
}

我的路线

@Component
public class RestAPI extends RouteBuilder {

    @Override
    public void configure() {
        restConfiguration().contextPath("/camel-rest-jpa").apiContextPath("/api-doc")
                .apiProperty("api.title", "Camel REST API")
                .apiProperty("api.version", "1.0")
                .apiProperty("cors", "true")
                .apiContextRouteId("doc-api")
                .bindingMode(RestBindingMode.json);


        rest("/books").description("Books REST service")
                .get("/").description("The list of all the books")
                .route().routeId("books-api")
                .bean(Database.class, "findBooks")
                .endRest()
                .get("order/{id}").description("Details of an order by id")
                .route().routeId("order-api")
                .bean(Database.class, "findOrder(${header.id})");


    }
}

我的后路

@Component
public class Backend extends RouteBuilder {

    @Override
    public void configure() {


        // A first route generates some orders and queue them in DB
        from("timer:new-order?delay=1s&period={{example.generateOrderPeriod:2s}}")
                .routeId("generate-order")
                .bean("orderService", "generateOrder")
                .to("jpa:org.apache.jms.example.spring.boot.rest.jpa.Order")
                .log("Inserted new order ${body.id}");

        // A second route polls the DB for new orders and processes them
        from("jpa:org.apache.jms.example.spring.boot.rest.jpa.Order"
                + "?consumer.namedQuery=new-orders"
                + "&consumer.delay={{example.processOrderPeriod:5s}}"
                + "&consumeDelete=false")
                .routeId("process-order")
                .log("Processed order #id ${body.id} with ${body.amount} copies of the «${body.book.description}» book");

    }
}

马文

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-activemq</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-pool</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jms-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jms</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-servlet-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
            <version>3.1.12</version>
        </dependency>

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-features-logging</artifactId>
            <version>3.1.12</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-test-spring</artifactId>
            <version>${camel.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jackson-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jpa-starter</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-csv</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-swagger-java-starter</artifactId>
            <version>${camel.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.hibernate</groupId>
                    <artifactId>hibernate-validator</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-servlet</artifactId>
            <version>${camel.version}</version>
        </dependency>
    </dependencies>

我犯了个错误

2018-06-25 14:44:47.460  WARN 13696 --- [mer://new-order] o.a.camel.component.timer.TimerConsumer  : Error processing exchange. Exchange[ID-IZeno-NB1048-1529912673553-0-5]. Caused by: [javax.persistence.TransactionRequiredException - No local transaction to join]

javax.persistence.TransactionRequiredException: No local transaction to join
    at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.doJoinTransaction(ExtendedEntityManagerCreator.java:388) ~[spring-orm-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:330) ~[spring-orm-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at com.sun.proxy.$Proxy121.joinTransaction(Unknown Source) ~[na:na]
    at org.apache.camel.component.jpa.JpaProducer$2.doInTransaction(JpaProducer.java:213) ~[camel-jpa-2.21.1.jar:2.21.1]
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133) ~[spring-tx-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.apache.camel.component.jpa.JpaProducer.processEntity(JpaProducer.java:210) ~[camel-jpa-2.21.1.jar:2.21.1]
    at org.apache.camel.component.jpa.JpaProducer.process(JpaProducer.java:162) ~[camel-jpa-2.21.1.jar:2.21.1]
    at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61) ~[camel-core-2.21.1.jar:2.21.1]
    at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:148) ~[camel-core-2.21.1.jar:2.21.1]
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548) ~[camel-core-2.21.1.jar:2.21.1]
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) [camel-core-2.21.1.jar:2.21.1]
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:138) ~[camel-core-2.21.1.jar:2.21.1]
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:101) ~[camel-core-2.21.1.jar:2.21.1]
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) [camel-core-2.21.1.jar:2.21.1]
    at org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:197) [camel-core-2.21.1.jar:2.21.1]
    at org.apache.camel.component.timer.TimerConsumer$1.run(TimerConsumer.java:79) [camel-core-2.21.1.jar:2.21.1]
    at java.util.TimerThread.mainLoop(Timer.java:555) [na:1.8.0_161]
    at java.util.TimerThread.run(Timer.java:505) [na:1.8.0_161]

下面是https://github.com/apache/camel/tree/master/examples/camel-example-spring-boot-rest-jpa但是我没有使用Spring Boot 2.0.3,我使用的是1.5.10。

使现代化

我意识到我有一个jmtransactionmanager

@Bean
    public JmsTransactionManager jmsTransactionManager(final ConnectionFactory connectionFactory) {
        JmsTransactionManager jmsTransactionManager = new JmsTransactionManager();
        jmsTransactionManager.setConnectionFactory(connectionFactory);
        return jmsTransactionManager;
    }

我需要为Jpa定义额外的transactionManager吗?还需要什么?

共有1个答案

赫连俊雄
2023-03-14

要集成数据库并使用它,您的JmsTransactionManager不合适。你需要一个DataSourceTransactionManager

我没有看到任何发送或使用JMS的路由。如果您根本不使用JMS,则不需要JmsTransactionManager

 类似资料:
  • 支持项 完全支持非跨库事务,例如:仅分表,或分库但是路由的结果在单库中; 完全支持因逻辑异常导致的跨库事务。例如:同一事务中,跨两个库更新。更新完毕后,抛出空指针,则两个库的内容都能回滚。 不支持项 不支持因网络、硬件异常导致的跨库事务。例如:同一事务中,跨两个库更新,更新完毕后、未提交之前,第一个库宕机,则只有第二个库数据提交。

  • 我使用了,但对于当前的问题,它没有帮助。我希望能够创建特定于项目的包: 我尝试了多种方法,但如何获得

  • 我正在运行TestCafe测试并排除与LocalTesting相关的BrowserStack故障(https://www.browserstack.com/local-testing). 我不想在测试运行中使用LocalTesting。 在阅读TestCafe的BrowserStack插件及其源代码(https://github.com/DevExpress/testcafe-browser-pr

  • 首先让我们先把代码拿出来。 很奇怪。此外,链接站点中的一些建议将本地apache deployemtn破坏到服务器将关闭的位置。只是看看是否有人有任何洞察力,因为我找不到任何好的数据,当搜索云铸造404。

  • 我想要做单词翻译(是的,只要单词翻译,可以不管句子) 看了一个 python 下的包/库,都是封装了谷歌翻译/有道翻译/百度翻译 但是,我想要一个可以本地化的翻译工具,不联网的 有什么包/库吗?如果没有 python 的,也可以是其他语言的

  • 在我的Spring Boot应用程序中,我有以下场景: 从JMS队列读取消息 对数据做一些事情。 对Oracle数据库执行JDBC插入 如果在任何阶段发生异常,我希望确保消息没有丢失并被放置在后退队列中。 我是否需要在启用XA的JMS连接工厂和启用XA的Oracle db驱动程序之间进行XA事务?或者使用例如DefaultMessageListenerContainer并将setsionTrans