对于我的带有嵌入式tomcat的Spring启动应用程序,由于某些限制,我需要废除 spring-boot-maven-plugin并需要使用maven-shade-plugin.使用maven package命令,我可以成功创建jar文件.但是,我的所有控制器都停止工作,并给我404错误.此外,我的资源文件夹中的静态内容不再提供.总是得到404错误.
我的pom.xml
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.2.7.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>abc.MyMainClass</mainClass>
</transformer>
</transformers>
</configuration>
</execution> …Run Code Online (Sandbox Code Playgroud) 我有一个非常标准的Spring Boot应用程序(application.properties属性文件位于标准/src/main/resources文件夹中),我将其作为"胖JAR"部署在AWS Elastic Beanstalk上.它工作得很好,但是服务器上的图像上传存在问题.经过一些调查后,似乎需要调整NGINX配置(增加到client_max_body_size可以接受上传的内容10MB),因此我添加了一个带有以下内容的文件.ebextensions夹/src/main/resources(取自此答案): -
files:
"/etc/nginx/conf.d/proxy.conf":
mode: "000755"
owner: root
group: root
content: |
client_max_body_size 20M;
Run Code Online (Sandbox Code Playgroud)
但是,当我运行mvn我的构建时,它不会.ebextensions在根文件夹中创建,我想知道什么是最佳解决方案.我的pom.xml文件很小,目前包含以下内容:
...
<packaging>jar</packaging>
....
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.6.RELEASE</version>
</dependency>
</dependencies>
</plugin>
Run Code Online (Sandbox Code Playgroud)
提前致谢!
@Lorena当我<resources> ...向我插入XML pom.xml然后启动服务器时,它崩溃了以下内容: -
2017-03-20 21:40:29.504 WARN 10784 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: …Run Code Online (Sandbox Code Playgroud) spring-boot amazon-elastic-beanstalk spring-boot-maven-plugin
从Spring Boot 1.3.7升级到1.4.0之后,我们再也无法使用Spring Boot Maven插件将我们的应用程序作为单个jar构建启动.我们的应用程序是使用Jersey和Jetty的小型REST接口.我们使用Maven,我们的pom文件非常标准的Spring Boot.
我们仍然可以mvn spring-boot:run在Eclipse中使用和运行应用程序,但是当作为单个jar运行时,Jersey会ResourceFinder抱怨它无法找到.jar!/BOOT-INF/classes.
当我解压缩jar时,文件夹BOOT-INF/classes存在并包含预期的类和资源.
任何帮助赞赏.
2016-08-10 14:58:31.162 ERROR 16071 --- [ main] o.s.boot.SpringApplication
: Application startup failed
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'jerseyConfig' defined in URL
[jar:file:/acmesource/acme/acme-core/acme-core-api/target/acme-core-api-0.1
SNAPSHOT.jar!/BOOT-INF/classes!/com/acme/core/api/JerseyConfig.class]: Bean
instantiation via constructor failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to instantiate
[com.acme.core.api.JerseyConfig]: Constructor threw exception; nested
exception is
org.glassfish.jersey.server.internal.scanning.ResourceFinderException:
java.io.FileNotFoundException: /acmesource/acme/acme-core/acme-core
api/target/acme-core-api-0.1-SNAPSHOT.jar!/BOOT-INF/classes (No such file or directory)
Run Code Online (Sandbox Code Playgroud) 所以我试图在另一个项目(测试框架)中添加一个spring boot可执行jar作为依赖项.
但是一旦添加到pom并导入.Java导入无法正常工作.如果我在罐子里面查看所有包装前面都有:
BOOT-INF/classes.some.package.classname.class
还有一些与春靴相关的包,MANIFEST等.
如果我将spring boot app的构建切换为使用spring-boot-maven-plugin安装和部署常规jar,
这种变化,一切正常.不幸的是,这不是我们的解决方案,因为我们依靠可执行jar作为发布过程的一部分.
我可以构建一个部署jar的两个版本并使用分类器来确定每个版本吗?
谢谢
注意:在将此问题标记为重复之前,请确保您知道可执行JAR与完全可执行的SpringBoot JAR之间的区别.
官方的Spring Boot文档描述了如何构建完全可执行的JAR.然后生成的JAR文件可以/etc/init.d/作为普通的unix服务链接和启动/停止/重新启动/统计,而无需其他脚本或工具(如JSVC).
但是生成的JAR包含所有库,并且可以足够大(在我的情况下为70Mb +).
我想生成没有库的完全可执行的JAR,但是能够在Linux上以SystemV服务的形式运行它并以某种方式链接外部库(JAR).
UPDATE
我想减少工件大小,以加快deploy-> test-> fix cycle.有时我通过移动网络工作,大文件大小会大大降低我的工作速度.
如果没有简单的配置属性或配置文件或命令行选项,我会使用一种黑客.
一开始,我可以生成一个包含所有依赖项的构建.然后我可以解压缩它并将所有库移动到一个特殊的文件夹.
然后我需要以某种方式再次打包它作为完全可执行文件并运行指向带有库的文件夹.
我不认为这可以用jar实用file程序完成,因为实用程序将完全可执行的jar识别为data
$ file fully-executable.jar
file fully-executable: data
Run Code Online (Sandbox Code Playgroud)
不像通常的罐子
$ file usual.jar
usual.jar: Java Jar file data (zip)
Run Code Online (Sandbox Code Playgroud) java executable-jar maven spring-boot spring-boot-maven-plugin
是否有可能以某种方式配置spring boot maven插件以包含来自依赖项的资源.
例如,如果在我的春季启动项目中,我有:
<dependency>
<groupId>co.company</groupId>
<artifactId>example</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
在那个JAR文件中有一个属性文件,如 example.properties
jar -tf example.jar | grep example.properties | wc -l
Run Code Online (Sandbox Code Playgroud)
结果1.
但是,当我构建Spring引导JAR时,此属性文件不会添加到src/main/resources.包含它的JAR包含在中BOOT-INF/lib/example.jar
但是,在我的情况下.我想将src/main/resourcesout 的内容解压缩到BOOT-INF/classes/spring boot JAR 的boot 目录中,这样自动配置之类的东西就可以把它拿出来.
在现实世界中,我正在尝试这样做:
src/main/resources引导JAR中).在这里,我在 Spring 工具套件中使用 Spring Boot。我想将 Oracle 数据库表转换为 JPA 类实体。但是我在 project_folder ->jpa 工具中没有得到任何 JPA 工具。我必须做什么,请您提出更好的解决方案。谢谢
运行我的jar文件时:java -jar target / places-1.0-SNAPSHOT.jar我遇到下一个错误:
no main manifest attribute, in target/places-1.0-SNAPSHOT.jar
Run Code Online (Sandbox Code Playgroud)
我的pom.xml包含spring-boot-maven-plugin:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.places.Main</mainClass>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我也试图创建一个MANIFEST.MF文件并指定该类,但是它没有帮助。
另外,我还尝试了:
<properties>
<!-- The main class to start by executing "java -jar" -->
<start-class>com.places.Main</start-class>
</properties>
Run Code Online (Sandbox Code Playgroud)
我的主要:
@SpringBootApplication
public class Main {
public static void main(String[] args) throws InterruptedException {
SpringApplication.run(Main.class,args);
}
}
Run Code Online (Sandbox Code Playgroud)
你知道我还能尝试什么吗?
我的 Spring Boot 项目包含 Spring Boot Maven 插件,我使用它通过运行mvn spring-boot:build-image.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>build-image</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
将此映像部署到 Docker 堆栈时,我需要使用该curl命令运行运行状况检查,但不幸的curl是默认构建包未安装该命令。
是否可以进一步调整图像构建过程,以便curl安装到图像中?我找不到必要的信息
使用 Spring Boot 2.4.0,我尝试配置spring-boot:build-image任务以将图像推送到我的私有 GitHub 容器注册表。
我使用这些说明来配置我的 POM,如下所示:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<name>ghcr.io/abc/${project.artifactId}:${project.version}</name>
<publish>true</publish>
</image>
<docker>
<publishRegistry>
<username>abc</username>
<token>mytoken</token>
<url>https://ghcr.io</url>
</publishRegistry>
</docker>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
当我执行spring-boot:build-image任务时,它会构建图像,但当它尝试推送时出现以下错误:
[INFO] Successfully built image 'ghcr.io/abc/def:1.5.0'
[INFO]
[INFO] > Pushing image 'ghcr.io/abc/def:1.5.0' 100%
Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:2.4.0:build-image failed: Error response received when pushing image: error parsing HTTP 405 response body: unexpected end of JSON input: "" -> [Help 1]
Run Code Online (Sandbox Code Playgroud)
我可以使用手动推送图像docker push,并且我尝试过这样做docker login也没有帮助。我也没有位于任何防火墙或代理后面。