试图通过喜欢gradlew clean build bootRun或者简单地gradlew bootRun显示gradle/java进程在没有提示的情况下退出/崩溃.除了以下内容外,不会显示其他错误或日志:
"/ Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/bin/java以非零退出值1完成".
gradlew bootRun --debug然而,运行显示BootRun(Gradle的JavaExec的扩展)任务似乎想要生成非常非常非常长的Classpath条目,最终会轰炸Java进程.
Spring Boot文档指定:
要在不构建jar的情况下运行项目,可以使用"bootRun"任务
但是,如果插件要生成如此长的类路径,那么这种方法似乎不起作用.
这个项目可能会证明这个问题:
https://github.com/apereo/cas-gradle-overlay-template
在cas/build.gradle文件中,可以添加依赖项来观察行为:
compile "org.apereo.cas:cas-server-support-json-service-registry:${project.'cas.version'}"
该项目包含以下依赖项:
dependencies {
compile "somewhere:something:somehow@war"
}
这根本没有问题bootRun; 但是,当任何其他编译/运行时依赖项添加到项目时,所有依赖项都可以传递或以其他方式添加到类路径中bootRun以便执行.
我也尝试创建一个"路径"JAR,希望插件/ Java可以简单地使用该Class-PathJAR清单中的条目来运行Web应用程序,并且传递给java命令的类路径条目将会缩短.然而,这并没有产生任何影响,java只是再次崩溃.
请注意,将Web应用程序作为可执行jar运行,java -jar app.war可以很好地处理所有依赖项等.
让其他人遇到类似问题吗?
java gradle spring-boot spring-boot-maven-plugin spring-boot-gradle-plugin
在spring-boot-maven-plugin的版本1.3.8.RELEASE和版本1.4.0.RELEASE之间 - 生成的包结构发生了变化(如果你提取uber jar文件)1.3.8.RELEASE com, lib,META-INF和org目录1.4.0.RELEASE有一个BOOT-INF,META-INF和org目录,基本上是从1.4.0.RELEASE开始 - 所有的类和库都在BOOT-INF目录中.因此 - 当您尝试在Amazon Lambda上运行Spring Boot项目时 - 它说有一个未找到的jar,因为它无法读取新的Spring Boot Uber jar结构
我的问题是 - 是否有可能在较新版本的Spring Boot Maven插件中生成uber jar,使其与版本1.3.9.RELEASE中的结构相同?
我尝试了maven-shade-plugin - 但这导致了其他问题
任何帮助是极大的赞赏
谢谢Damien
我正在使用Netbeans 8.2来开发Spring应用程序.我遇到问题的这个特定应用程序是一个Spring Boot 1.5.3应用程序.我有一个spring xml文件和一个application.properties,我保存在根项目目录下的/ config中.
我通过@ImportResource注释和值属性将spring xml文件传递给我的项目@ImportResource(value="${config.xmlfile}").
当我单击Netbeans中的"运行项目"按钮时,我的Spring应用程序启动并正确找到我的/ config文件夹中的application.properties文件.但是,对该文件夹中其他文件的任何类路径引用都将丢失.例如,将config.xml文件设置为classpath:config/file.xml或classpath:file.xml两者都无法找到该文件但file:config/file.xml有效.
同样,从命令行运行时,我的结构如下:
app/
|-- bin
| `-- app-run.sh
|-- config
| |-- application.properties
| |-- log4j2.xml
| |-- file.xml
`-- app-exec.jar
Run Code Online (Sandbox Code Playgroud)
我正在使用spring-boot-maven-plugin如下制作jar:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我的app-run.sh脚本执行以下操作:
exec /bin/java -cp :.:../config/*:../app-exec.jar
-Dlogging.config=../config/log4j2.xml
-Dspring.config.location=../config/application.properties
-jar ../app-exec.jar
Run Code Online (Sandbox Code Playgroud)
其中/ bin/java表示我安装java的位置.在-cp中设置的类路径似乎不起作用.与通过IDE运行时类似,将config.xml文件设置为classpath:config/file.xml或classpath:file.xml都无法找到文件,但文件:../ config/file.xml有效.
我希望能够在IDE和命令行中设置类路径,以便我可以使用类路径引用访问Spring中的文件,以简化操作.我不想将它们全部放入src/main/resources并将它们打包在jar中,因为我需要在打包和部署后编辑它们.
有没有人有任何想法或有用的提示?提前致谢!
我有一个带有球衣依赖项的项目春季启动:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
当我执行spring-boot:run所有操作时,所有上下文都将变得完美,一切正常。
当我使用打包该项目时mvn package,就会出现问题,因为requiresUnpack没有打开球衣的依赖关系。这是解决这个问题的必要条件:https : //github.com/spring-projects/spring-boot/issues/1468
在pom.xml中,我使用:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<requiresUnpack>
<!-- dependencies that I want to unpack -->
</requiresUnpack>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
然后,当我执行java -jar jarBoot.jar控制台输出为:
2019-05-02 15:02:46.218 ERROR 17476 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : StandardWrapper.Throwable
org.glassfish.hk2.api.MultiException: A MultiException has 1 exceptions. They are:
1. org.glassfish.jersey.server.internal.scanning.ResourceFinderException: java.io.FileNotFoundException: C:\Users\Francesc\microservices git\sidecar-base\target\sidecar-base-0.0.1-SNAPSHOT.jar!\BOOT-INF\classes (El sistema no puede encontrar la ruta especificada)
at org.jvnet.hk2.internal.Utilities.justCreate(Utilities.java:1009) ~[hk2-locator-2.5.0-b32.jar!/:na]
at org.jvnet.hk2.internal.ServiceLocatorImpl.create(ServiceLocatorImpl.java:975) ~[hk2-locator-2.5.0-b32.jar!/:na] …Run Code Online (Sandbox Code Playgroud) 我有一个多模块 Maven 项目,其中包含一个由多个 Spring Boot 服务组成的应用程序。我正在尝试为服务设置集成和端到端测试,并且正在使用组合 Maven 插件来进行协调。
我有一个模块,旨在仅包含对执行某些工作的协作服务组的端到端测试。它只包含测试代码和资源。我正在使用故障安全插件 ( org.apache.maven.plugins:maven-failsafe-plugin) 来执行集成测试,使用 Spring Boot Maven 插件 ( org.springframework.boot:spring-boot-maven-plugin) 来启动和停止“主要”服务,并使用 Maven exec 插件 ( org.codehaus.mojo:exec-maven-plugin) 来启动最后正在使用的其他服务- 端到端测试。
我遇到了一个似乎与repackageSpring Boot 插件的目标有关的问题。e2e 模块没有什么需要重新打包的,所以我想跳过这个目标。应该不会太难吧?
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<skip>true</skip>
</configuration>
<execution>
...
Run Code Online (Sandbox Code Playgroud)
嗯,这行不通。尽管如此,它仍然运行重新打包。
问题在于 Maven 构建失败,因为它找不到要重新打包的“主”类(我相信作为可执行 jar)。那么,有是这个模块没有主类。
更重要的问题是:为什么会<skip>true</skip>被忽视?
我正在尝试使用命令构建 docker 映像mvn spring-boot:build-image -P<environment>,但出现错误:
[INFO] [creator] Paketo BellSoft Liberica Buildpack 8.1.2
[INFO] [creator] https://github.com/paketo-buildpacks/bellsoft-liberica
[INFO] [creator] Build Configuration:
[INFO] [creator] $BP_JVM_VERSION 8.* the Java version
[INFO] [creator] Launch Configuration:
[INFO] [creator] $BPL_JVM_HEAD_ROOM 0 the headroom in memory calculation
[INFO] [creator] $BPL_JVM_LOADED_CLASS_COUNT 35% of classes the number of loaded classes in memory calculation
[INFO] [creator] $BPL_JVM_THREAD_COUNT 250 the number of threads in memory calculation
[INFO] [creator] $JAVA_TOOL_OPTIONS the JVM launch flags
[INFO] [creator] BellSoft Liberica JRE 8.0.292: Contributing …Run Code Online (Sandbox Code Playgroud) 我需要使用spring-boot:build-imageand将自签名证书添加到 spring-boot docker 映像中paketo-buildpacks/ca-certificates,但无法使其工作。
所以:
paketo-buildpacks/ca-certificates绑定?mvn spring-boot:build-image?到目前为止我尝试过但没有成功:更新 pom.xml spring-boot-maven-plugin:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<bindings>
<binding>${basedir}/bindings/ca-certificates:/platform/bindings/ca-certificates</binding>
</bindings>
</image>
</configuration>
<executions>
<execution>
<goals>
<goal>build-image</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
来自${basedir}文件夹:
mkdir bindings
mkdir bindings/ca-certificates
echo "ca-certificates" > bindings/ca-certificates/type
cp ~/.ssh/mycert.pem bindings/ca-certificates/
mvn spring-boot:build-image
Run Code Online (Sandbox Code Playgroud)
编辑:按照 @nick-valanos 的建议,将图像绑定配置直接移动到 boot-plugin 下(而不是在特定执行中)并解决了问题。
运行 Maven 包目标时
mvn清理包
构建抛出错误:
目标 org.springframework.boot:spring-boot-maven-plugin:3.0.0-M1:repackage 失败:无法加载插件 'org.springframework.boot:spring-boot-maven-plugin 中的 mojo 'repackage': 3.0.0-M1' 由于 API 不兼容:org.codehaus.plexus.component.repository.exception.ComponentLookupException:org/springframework/boot/maven/RepackageMojo 已由更新版本的 Java 运行时(类文件版本 61.0),此版本的 Java 运行时仅识别 52.0 以下的类文件版本
我的 JAVA_HOME 指向 jdk1.8.0_73
我怎样才能让 spring-boot-maven-plugin 以重新打包的目标运行?
下面是我的模块中的 Maven 构建配置。
<build>
<resources>
<resource>
<directory>resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
<webResources>
<resource>
<directory>src/main/resources</directory>
<include>*.*</include>
<targetPath>/WEB-INF/classes</targetPath>
</resource>
<resource>
<directory>src/main/webapp/errors</directory>
<include>*.*</include>
<targetPath>/errors/</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.services.MyAApp</mainClass>
<layout>war</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals> …Run Code Online (Sandbox Code Playgroud) java maven spring-boot maven-package spring-boot-maven-plugin
我正在尝试运行我的第一个 springboot 应用程序,但面临一些问题。
在我的应用程序文件中,这是我的代码
package com.clog.ServiceMgmt;
import java.util.List;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@SpringBootApplication
@EntityScan("models")
@ComponentScan({"com.clog.ServiceMgmt","controllers", "models", "repositories"})
@EnableJpaRepositories(basePackages={"repositories"})
public class ServiceMgmtApplication {
public static void main(String[] args) {
SpringApplication.run(ServiceMgmtApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行我的应用程序时,我收到以下错误。对为什么我应该得到这个错误以及如何解决它感到困惑。
org.springframework.core.annotation.AnnotationConfigurationException:注释 [org.springframework.boot.autoconfigure.SpringBootApplication] 中的属性“proxyBeanMethods”在注释 [org.springframework.context.annotation.Configuration] 中被声明为 @AliasFor 不存在的属性“proxyBeanMethods” ].; 嵌套异常是 java.lang.NoSuchMethodException: org.springframework.context.annotation.Configuration.proxyBeanMethods()
这是我的 pom.xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.BUILD-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.clog</groupId>
<artifactId>ServiceMgmt</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>ServiceMgmt</name>
<description>Service …Run Code Online (Sandbox Code Playgroud) 我正在使用 Spring Boot 3.1.5、 Java21和 maven 3.9.5。我运行时出现以下错误mvn spring-boot:build-image
[INFO] > Pulling builder image 'docker.io/paketobuildpacks/builder:base' 100%
[INFO] > Pulled builder image 'paketobuildpacks/builder@sha256:17ea21162ba8c7717d3ead3ee3836a368aced7f02f2e59658e52029bd6d149e7'
[INFO] > Pulling run image 'docker.io/paketobuildpacks/run:base-cnb' 100%
[INFO] > Pulled run image 'paketobuildpacks/run@sha256:1af9935d8987fd52b2266d288200c9482d1dd5529860bbf5bc2d248de1cb1a38'
[INFO] > Executing lifecycle version v0.16.5
[INFO] > Using build cache volume 'pack-cache-8847f704ad41.build'
[INFO]
[INFO] > Running creator
[INFO] [creator] ===> ANALYZING
[INFO] [creator] Image with name "docker.io/library/elevate-insights:0.0.1-SNAPSHOT" not found
[INFO] [creator] ===> DETECTING
[INFO] [creator] 6 of 26 buildpacks participating …Run Code Online (Sandbox Code Playgroud)