java rg.apache.maven.lifecycle.LifecycleExecutionException:执行目标失败

eqqqjvef  于 2023-09-29  发布在  Java
关注(0)|答案(1)|浏览(103)

我是Java和Maven/Spring的新手。我正在构建一个项目,以使用委托在Camunda中运行BPMN流程。我已经写了代码,建立了依赖关系,并试图建立项目。当我将JAR文件放入Camunda容器(我将Camunda部署在Linux服务器上)时,我不断收到一个错误:表达式中使用了未知属性:${sqlDataRetrievalDelegate}。原因:无法解析标识符'sqlDataRetrievalDelegate'
在我看来,我的Spring没有扫描和创建Bin,我做错了什么?请帮帮我
下面是我的pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.camunda.bpm.getstarted</groupId>
    <artifactId>loan-approval-spring-boot</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <camunda.spring-boot.version>7.19.0</camunda.spring-boot.version>
        <spring-boot.version>2.7.10</spring-boot.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <mssql.jdbc.version>9.2.1.jre11</mssql.jdbc.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.camunda.bpm.springboot</groupId>
            <artifactId>camunda-bpm-spring-boot-starter-webapp</artifactId>
            <version>${camunda.spring-boot.version}</version>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.3.6</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>${mssql.jdbc.version}</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${spring-boot.version}</version>
                <configuration>
                    <mainClass>com.myapp.sqlDataRetrievalDelegate</mainClass>
                    <layout>ZIP</layout>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

下面是我的JAVA代码:

package com.myapp;

import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Arrays;
import java.util.List;

@Component("sqlDataRetrievalDelegate")
public class sqlDataRetrievalDelegate implements JavaDelegate {
    private static final Logger logger = LoggerFactory.getLogger(sqlDataRetrievalDelegate.class);

    @Override
    public void execute(DelegateExecution execution) {
        logger.info("Executing SQL data retrieval delegate...");

        String jdbcUrl = "jdbc:sqlserver://10.100.11.11:1433;databaseName=DBtestData";
        String username = "camunda_sql1111";
        String password = "12345678";

        List<String> tags = Arrays.asList("MATR_TAG00001.SIM", "MATR_TAG00002.SIM", "MATR_TAG00003.SIM", "MATR_TAG00004.SIM");

        try (Connection conn = DriverManager.getConnection(jdbcUrl, username, password)) {
            String query = buildQuery(tags);

            try (PreparedStatement stmt = conn.prepareStatement(query)) {
                try (ResultSet rs = stmt.executeQuery()) {
                    while (rs.next()) {
                        String tagName = rs.getString("TagName");
                        String timeStamp = rs.getString("TimeStamp");
                        double value = rs.getDouble("Value");

                        execution.setVariable("tagNameVariable", tagName);
                        execution.setVariable("timeStampVariable", timeStamp);
                        execution.setVariable("valueVariable", value);
                    }
                }
            }
        } catch (Exception e) {
            logger.error("Failed to execute SQL delegate", e);
            throw new RuntimeException("Failed to execute SQL delegate", e);
        }
    }

    private String buildQuery(List<String> tags) {
        StringBuilder queryBuilder = new StringBuilder("SELECT TagName, TimeStamp, Value FROM OPENQUERY (PHD_OLEDB, 'SELECT * FROM phd.phd_data WHERE tagname IN (");
        for (int i = 0; i < tags.size(); i++) {
            queryBuilder.append("''").append(tags.get(i)).append("''");
            if (i < tags.size() - 1) {
                queryBuilder.append(",");
            }
        }
        queryBuilder.append(") AND raw_data = true')");

        return queryBuilder.toString();
    }
}

以下是我在IDEA中看到的日志:

PS C:\Users\FilippovAn\untitled1> mvn -e spring-boot:run
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] 
[INFO] --------< org.camunda.bpm.getstarted:loan-approval-spring-boot >--------
[INFO] Building loan-approval-spring-boot 0.0.1-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] >>> spring-boot:2.7.10:run (default-cli) > test-compile @ loan-approval-spring-boot >>>
[INFO] 
[INFO] --- resources:3.3.1:resources (default-resources) @ loan-approval-spring-boot ---
[WARNING] Using platform encoding (Cp1251 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources from src\main\resources to target\classes
[INFO]
[INFO] --- compiler:3.11.0:compile (default-compile) @ loan-approval-spring-boot ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- resources:3.3.1:testResources (default-testResources) @ loan-approval-spring-boot ---
[WARNING] Using platform encoding (Cp1251 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\FilippovAn\untitled1\src\test\resources
[INFO]
[INFO] --- compiler:3.11.0:testCompile (default-testCompile) @ loan-approval-spring-boot ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] <<< spring-boot:2.7.10:run (default-cli) < test-compile @ loan-approval-spring-boot <<<
[INFO]
[INFO]
[INFO] --- spring-boot:2.7.10:run (default-cli) @ loan-approval-spring-boot ---
[INFO] Attaching agents: []
Error: Main method not found in class com.myapp.sqlDataRetrievalDelegate, please define the main method as:
   public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.102 s
[INFO] Finished at: 2023-08-18T11:30:12+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.7.10:run (default-cli) on project loan-approval-spring-boot: Application finished with exit code:
 1 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.7.10:run (default-cli) on project loan-approval-s
pring-boot: Application finished with exit code: 1
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:333)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
Caused by: org.apache.maven.plugin.MojoExecutionException: Application finished with exit code: 1
    at org.springframework.boot.maven.RunMojo.runWithForkedJvm (RunMojo.java:103)
    at org.springframework.boot.maven.AbstractRunMojo.doRunWithForkedJvm (AbstractRunMojo.java:291)
    at org.springframework.boot.maven.AbstractRunMojo.run (AbstractRunMojo.java:255)
    at org.springframework.boot.maven.AbstractRunMojo.execute (AbstractRunMojo.java:225)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

这些是我在Camunda看到的日志:

2023-08-15 12:15:02.465  WARN 10 --- [aTaskExecutor-3] org.camunda.bpm.engine.jobexecutor       : ENGINE14006 Exception while executing job acf3efa9-3b64-11ee-8bf4-0242ac120002:
org.camunda.bpm.engine.ProcessEngineException: Unknown property used in expression: ${sqlDataRetrievalDelegate}. Cause: Cannot resolve identifier 'sqlDataRetrievalDelegate'
esbemjvw

esbemjvw1#

在spring-boot-maven-plugin的配置中的pom.xml中,您将mainClass指定为com.myapp.sqlDataRetrievalDelegate(顺便说一下,在Java中,常见的做法是以大写字母开始类名,因此com.myapp.SqlDataRetrievalDelegate)。
对于spring Boot 应用程序,您需要一个application class(参见https://spring.io/guides/gs/spring-boot/)。
例如,将mainClass定义为com.myapp.Application,该类应该如下所示:

package com.myapp;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

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

这还将启用组件扫描并拾取您的委托bean。

相关问题