• 使用spring-boot-dependencies代替spring-boot-starter-parent,jar启动报错 没有主清单属性解决


    maven项目中不使用spring-boot-starter-parent作为上级项目,改为导入spring-boot-dependencies管理依赖

    <dependencyManagement>
    	<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>${spring-boot.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencyManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    项目构建后,直接执行jar包会报错:

    jar中没有主清单属性

    此外还会遇到如无法在配置文件中使用maven占位符等问题

    version: @project.version@
    
    • 1

    报错:

    ERROR org.springframework.boot.SpringApplication - Application run failed
    org.yaml.snakeyaml.scanner.ScannerException: while scanning for the next token
    found character ‘@’ that cannot start any token. (Do not use @ for indentation)
    in ‘reader’, line 1, column 10:
    version: @project.version@

    解决

    • 配置spring构建插件
    <build>
    	<plugin>
    	    <groupId>org.springframework.boot</groupId>
    	    <artifactId>spring-boot-maven-plugin</artifactId>
    	    <executions>
    	        <execution>
    	            <id>repackage</id>
    	            <goals>
    	                <goal>repackage</goal>
    	            </goals>
    	        </execution>
    	    </executions>
    	</plugin>
    </build>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 配置资源过滤,支持配置文件使用maven占位符
    <build>
    	<resources>
            <resource>
                <directory>${basedir}/src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/application*.yml</include>
                    <include>**/application*.yaml</include>
                    <include>**/application*.properties</include>
                </includes>
            </resource>
            <resource>
                <directory>${basedir}/src/main/resources</directory>
                <excludes>
                    <exclude>**/application*.yml</exclude>
                    <exclude>**/application*.yaml</exclude>
                    <exclude>**/application*.properties</exclude>
                </excludes>
            </resource>
        </resources>
    </build>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
  • 相关阅读:
    钢铁异常分类 few-shot 问题 小陈读paper 钢铁2
    模拟电子技术基础之场效应管
    SizeBasedTriggeringPolicy简介说明
    小规模自建 Elasticsearch 的部署及优化
    解析Flutter应用在iOS环境中的性能优化技巧
    2w+深度梳理!全网最全NLP面试题总结!
    新鲜出炉!ECCV2022 107个开源数据集合辑,全球 AI 研究热点一网打尽
    Azure Integrator Delphi版
    常见的缺陷管理工具——禅道,从安装到使用手把手教会你
    汇编语言与接口技术实验
  • 原文地址:https://blog.csdn.net/zhoudingding/article/details/125539274