Java 如何使用;“电源变压器”的属性;添加SpringBoot配置时使用maven shade插件<;依赖管理>;标签

Java 如何使用;“电源变压器”的属性;添加SpringBoot配置时使用maven shade插件<;依赖管理>;标签,java,spring,maven,spring-boot,maven-shade-plugin,Java,Spring,Maven,Spring Boot,Maven Shade Plugin,我正在使用maven shade插件和Sprint引导。我已将spring启动依赖项定义为: <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies

我正在使用maven shade插件和Sprint引导。我已将spring启动依赖项定义为:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>2.0.2.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
这清楚地表明,无法找到
属性mergingreourcetransformer
的实现。如果我使用
标签中定义的Spring引导配置,它就可以正常工作

但是,如果我完全删除maven shade插件配置中的
属性mergingreourceTransformer
配置,则无法执行捆绑jar,并给出如下异常:

`java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.
    at org.springframework.util.Assert.notEmpty(Assert.java:450) ~[myapp-1.0-SNAPSHOT.jar:na]
    at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getCandidateConfigurations(AutoConfigurationImportSelector.java:160) ~[myapp-1.0-SNAPSHOT.jar:na]
    at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.selectImports(AutoConfigurationImportSelector.java:96) ~[myapp-1.0-SNAPSHOT.jar:na]`
有人能帮忙吗

供参考:这是maven shade插件问题,已解决:

但只有在
标记中配置了spring启动依赖项,而不是
中配置了spring启动依赖项时,它才起作用

在尝试使用spring boot maven插件时,我在运行jar时遇到以下异常:

`Exception in thread "main" java.lang.IllegalStateException: Failed to get nested archive for entry BOOT-INF/lib/spring-boot-2.0.2.RELEASE.jar
    at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchive(JarFileArchive.java:108)
    at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchives(JarFileArchive.java:86)
    at org.springframework.boot.loader.ExecutableArchiveLauncher.getClassPathArchives(ExecutableArchiveLauncher.java:70)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:49)
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.io.IOException: Unable to open nested jar file 'BOOT-INF/lib/spring-boot-2.0.2.RELEASE.jar'
    at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:254)
    at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:239)
    at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchive(JarFileArchive.java:103)
    ... 4 more
Caused by: java.lang.IllegalStateException: Unable to open nested entry 'BOOT-INF/lib/spring-boot-2.0.2.RELEASE.jar'. It has been compressed and nested jar files must be stored without compression. Please check the mechanism used to create your executable jar file
    at org.springframework.boot.loader.jar.JarFile.createJarFileFromFileEntry(JarFile.java:282)
    at org.springframework.boot.loader.jar.JarFile.createJarFileFromEntry(JarFile.java:262)
    at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:250)
    ... 6 more`

希望你现在已经解决了这个问题,但是在我被同样的问题困扰了几个小时之后,我意识到
spring-boot-maven-plugin
作为
maven-shade-plugin
的依赖项是必需的:

<groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>${maven-shade-plugin.version}</version>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <version>${spring-boot.version}</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals><goal>shade</goal></goals>
                    <configuration>
                        <transformers>
                            <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.handlers</resource>
                            </transformer>
                            <transformer
                                    implementation="org.springframework.boot.maven.PropertiesMergingResourceTransformer">
                                <resource>META-INF/spring.factories</resource>
                            </transformer>
                            <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.schemas</resource>
                            </transformer>
                            <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                            <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>${start-class}</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
org.apache.maven.plugins
maven阴影插件
${maven shade plugin.version}
org.springframework.boot
springbootmaven插件
${spring boot.version}
包裹
阴凉处
META-INF/spring.handlers
META-INF/spring.com
META-INF/spring.schemas
${start class}

希望您现在已经解决了这个问题,但是在我被同样的问题困扰了几个小时之后,我意识到将
spring boot maven plugin
作为
maven shade plugin
的依赖项包括在内是必需的:

<groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>${maven-shade-plugin.version}</version>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <version>${spring-boot.version}</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals><goal>shade</goal></goals>
                    <configuration>
                        <transformers>
                            <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.handlers</resource>
                            </transformer>
                            <transformer
                                    implementation="org.springframework.boot.maven.PropertiesMergingResourceTransformer">
                                <resource>META-INF/spring.factories</resource>
                            </transformer>
                            <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.schemas</resource>
                            </transformer>
                            <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                            <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>${start-class}</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
org.apache.maven.plugins
maven阴影插件
${maven shade plugin.version}
org.springframework.boot
springbootmaven插件
${spring boot.version}
包裹
阴凉处
META-INF/spring.handlers
META-INF/spring.com
META-INF/spring.schemas
${start class}

为什么要在SpringBoot中使用maven shade插件?原因是什么?为什么不使用SpringBootMaven插件呢?你的回答是绝对正确的,我只尝试使用maven apache插件,但由于本stackoverflow中提到的这个问题,我无法使用它。抱歉,您是否尝试使用SpringBootMaven插件并发现问题?你有什么问题?你想在哪里运行spring boot应用程序?是的,我尝试使用spring boot maven插件,然后在将jar部署到服务器时,我发现了一个错误。已经更新了上面的问题。什么样的服务器?你已经建立了一个war文件了吗?为什么你要在SpringBoot中使用maven shade插件?原因是什么?为什么不使用SpringBootMaven插件呢?你的回答是绝对正确的,我只尝试使用maven apache插件,但由于本stackoverflow中提到的这个问题,我无法使用它。抱歉,您是否尝试使用SpringBootMaven插件并发现问题?你有什么问题?你想在哪里运行spring boot应用程序?是的,我尝试使用spring boot maven插件,然后在将jar部署到服务器时,我发现了一个错误。已经更新了上面的问题。什么样的服务器?你建立了战争档案吗?