【问题标题】:SImple Camel application is't not working whith Quartz componentSIMple Camel 应用程序不能使用 Quartz 组件
【发布时间】:2022-10-04 16:22:57
【问题描述】:

我正在尝试使用石英组件运行一个简单的骆驼路线来安排工作。在这个例子中就像每分钟打个招呼。

这是示例路线:

public void configure() throws Exception {
    from("quartz://myname?cron=0+ *+ *+ ?+ *+ *")
    .to("log:hello");
}

当我运行应用程序时,我收到以下错误:

 An attempt was made to call a method that does not exist. The attempt was made from 
 the following location:

org.apache.camel.component.quartz.QuartzComponent.createEndpoint(QuartzComponent.java:150)

 The following method did not exist:

'org.quartz.Trigger org.quartz.Scheduler.getTrigger(java.lang.String, java.lang.String)'

 The method's class, org.quartz.Scheduler, is available from the following locations:

jar:file:/C:/Users/andre/.m2/repository/org/quartz-scheduler/quartz/2.3.2/quartz-2.3.2.jar!/org/quartz/Scheduler.class

 The class hierarchy was loaded from the following locations:

org.quartz.Scheduler: file:/C:/Users/andre/.m2/repository/org/quartz-scheduler/quartz/2.3.2/quartz-2.3.2.jar


 Action:

 Correct the classpath of your application so that it contains a single, compatible 
 version of org.quartz.Scheduler

但实际上我不明白我应该如何更正我的应用程序的类路径。 这是 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.mycompany</groupId>
  <artifactId>camel-ose-springboot-xml</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <name>Fabric8 :: Quickstarts :: Spring-Boot :: Camel XML</name>
  <description>Spring Boot example running a Camel route defined in XML</description>
  <properties>
    <maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
    <docker.image.version>1.9</docker.image.version>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <fuse.version>7.11.0.fuse-sb2-7_11_0-00028-redhat-00001</fuse.version>
  </properties>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.jboss.redhat-fuse</groupId>
        <artifactId>fuse-springboot-bom</artifactId>
        <version>7.11.0.fuse-sb2-7_11_0-00028-redhat-00001</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
 
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-spring-boot-starter</artifactId>
    </dependency>
    <dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-quartz</artifactId>
    <!-- use the same version as your Camel core version -->
</dependency>
<dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      <exclusions>
        <exclusion>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-undertow</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
  </dependencies>
  <repositories>
    <repository>
      <id>red-hat-ga-repository</id>
      <url>https://maven.repository.redhat.com/ga</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <id>red-hat-ga-repository</id>
      <url>https://maven.repository.redhat.com/ga</url>
    </pluginRepository>
  </pluginRepositories>
  <build>
    <defaultGoal>spring-boot:run</defaultGoal>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>${maven-compiler-plugin.version}</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.jboss.redhat-fuse</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>${fuse.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>repackage</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <id>openshift</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.jboss.redhat-fuse</groupId>
            <artifactId>openshift-maven-plugin</artifactId>
            <version>${fuse.version}</version>
            <executions>
              <execution>
                <goals>
                  <goal>resource</goal>
                  <goal>build</goal>
                  <goal>apply</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <enricher>
                <excludes>
                  <exclude>fmp-openshift-route</exclude>
                </excludes>
              </enricher>
              <resources>
                <labels>
                  <pod>
                    <property>
                      <name>com.company</name>
                      <value>Red_Hat</value>
                    </property>
                    <property>
                      <name>rht.prod_name</name>
                      <value>Red_Hat_Integration</value>
                    </property>
                    <property>
                      <name>rht.prod_ver</name>
                      <value>7.9</value>
                    </property>
                    <property>
                      <name>rht.comp</name>
                      <value>spring-boot-camel-xml</value>
                    </property>
                    <property>
                      <name>rht.comp_ver</name>
                      <value>${fuse.bom.version}</value>
                    </property>
                  </pod>
                </labels>
              </resources>
            </configuration>
          </plugin>
        </plugins>
      </build>
      <properties>
        <jkube.generator.from>registry.redhat.io/fuse7/fuse-java-openshift-rhel8:${docker.image.version}</jkube.generator.from>
      </properties>
    </profile>
    <profile>
      <id>java11</id>
      <activation>
        <jdk>[11,)</jdk>
      </activation>
      <properties>
        <jkube.generator.from>registry.redhat.io/fuse7/fuse-java-openshift-jdk11-rhel8:${docker.image.version}</jkube.generator.from>
      </properties>
    </profile>
    <profile>
      <id>java17-build</id>
      <activation>
        <jdk>[17,)</jdk>
      </activation>
      <dependencies>
        <dependency>
          <groupId>com.sun.xml.bind</groupId>
          <artifactId>jaxb-impl</artifactId>
          <version>2.3.5</version>
        </dependency>
      </dependencies>
    </profile>
  </profiles>
</project>

【问题讨论】:

  • 那个版本的保险丝看起来真的很旧。可能想尝试更新的版本。另外,不要尝试camel-quartz,而是尝试camel-quartz-starter
  • 感谢您的回复,但它仍然无法正常工作

标签: java apache-camel quarkus


【解决方案1】:

Quartz 版本在某处存在冲突,实际上是您使用的 camel-quartz 版本 (2.23.2.fuse-7_11_0-00037-redhat-00001),预计 Quartz v1 而您最终使用的是导致问题的 Quartz v2。

您有两种方法可以解决您的问题:

  1. 继续使用 Quartz v1

    在这种情况下,你必须在你的 pom 文件中强制使用 Quartz 的版本,方法是添加:

    </dependency>
        <dependency>
          <groupId>org.quartz-scheduler</groupId>
          <artifactId>quartz</artifactId>
          <version>1.8.6</version>
        </dependency>
    <dependency>
    
    1. 切换到 Quartz v2

    在这种情况下,您必须将 camel-quartz 工件更改为 camel-quartz2-starter,如下所示:

    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-quartz2-starter</artifactId>
        <!-- use the same version as your Camel core version -->
    </dependency>
    

    然后通过指定 quartz2 而不是 quartz 来更改 Quartz 端点的 URI,如下所示:

    public void configure() throws Exception {
        from("quartz2://myname?cron=0+ *+ *+ ?+ *+ *")
        .to("log:hello");
    }
    

    选择取决于您,但我绝对建议切换到 Quartz v2。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-01
    相关资源
    最近更新 更多