You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot项目Jar运行时BeanCreationException问题求助

可行的Jar运行解决方案

针对你遇到的Spring Boot Jar启动时缺失Siddhi类的问题,以下是具体解决步骤:

1. 修正依赖Scope

检查pom.xml中Siddhi相关依赖的<scope>配置,若设置为provided,该依赖不会被打包进Jar包(IDEA运行时依赖由IDE环境提供),需移除该配置:

<!-- 错误示例 -->
<dependency>
    <groupId>org.wso2.siddhi</groupId>
    <artifactId>siddhi-annotations</artifactId>
    <version>x.x.x</version>
    <scope>provided</scope> <!-- 移除这一行 -->
</dependency>

<!-- 正确配置 -->
<dependency>
    <groupId>org.wso2.siddhi</groupId>
    <artifactId>siddhi-annotations</artifactId>
    <version>x.x.x</version>
</dependency>

2. 确保Spring Boot打包插件正确配置

使用spring-boot-maven-plugin时,需确保它能将所有依赖打包到可执行Jar中,添加includeAllDependencies配置(若未默认开启):

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>${spring-boot.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <includeAllDependencies>true</includeAllDependencies>
            </configuration>
        </plugin>
    </plugins>
</build>

3. 确认缺失类对应的依赖是否引入

ICommonAnnotationComposite类属于Siddhi的注解模块,需确保pom.xml中引入了对应的依赖:

<dependency>
    <groupId>org.wso2.siddhi</groupId>
    <artifactId>siddhi-annotations</artifactId>
    <version>4.1.24</version> <!-- 使用匹配你项目的版本 -->
</dependency>

4. 验证Jar包内容

执行以下命令检查生成的Jar包中是否包含缺失的类:

jar tf your-application.jar | grep ICommonAnnotationComposite

若输出为空,说明该类未被打包,回到步骤1-3排查依赖和打包配置;若有输出,检查类路径是否与代码引用一致。

5. 备选:使用Maven Assembly插件打包

若spring-boot-maven-plugin仍无法解决问题,可尝试maven-assembly-plugin生成包含所有依赖的可执行Jar:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.3.0</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>com.your.package.YourApplication</mainClass> <!-- 替换为你的主类 -->
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

打包后运行target/your-application-jar-with-dependencies.jar即可。

内容的提问来源于stack exchange,提问作者Nuvindu Nirmana

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 00:13:20