标签: spring-boot-maven-plugin

Spring Boot Maven插件-spring-boot:运行并正常关闭

我可以使用以下Maven命令运行Spring Boot应用程序:

mvn spring-boot:run 
Run Code Online (Sandbox Code Playgroud)

但我不知道如何正常关闭以这种方式启动的应用程序。请指教。

maven spring-boot spring-boot-maven-plugin

6
推荐指数
1
解决办法
3243
查看次数

如何通过maven-failsafe-plugin运行基于Spring Boot的应用程序的集成测试?

我有一个基于spring-boot的应用程序,并且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>

    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.7.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</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.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <classifier>exec</classifier>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.20.1</version>
                <configuration>
                    <includes>
                        <include>**/IT*.java</include>
                        <include>**/*IT.java</include>
                        <include>**/*ITCase.java</include>
                    </includes>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins> …
Run Code Online (Sandbox Code Playgroud)

java integration-testing maven-failsafe-plugin spring-boot spring-boot-maven-plugin

6
推荐指数
2
解决办法
7234
查看次数

在多模块Maven项目中共享公共模块

我有一个包含三个模块的项目:A、B 和 COMMON。我想将通用逻辑放入 COMMON 模块(例如模型)中,然后放入依赖于它的其他两个模块。

两个模块(A、B)将分别构建以创建两个不同的 jar。

我正在测试它,尝试将日志依赖项放入 COMMON 模块中,然后构建 A 项目。它将正确构建,但如果我尝试使用“java -jar a.jar”运行 jar,则会失败并显示 NoClassDefFound:

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
Run Code Online (Sandbox Code Playgroud)

根 pom:

<modules>
    <module>common</module>
    <module>a</module>
</modules>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.12</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.1.3</version>
        </dependency>
    </dependencies>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud)

常见的pom:

<dependencies>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
    </dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)

和一个pom:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                        <mainClass>bla.bla.Main</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>bla.blu</groupId>
        <artifactId>common</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)

java pom.xml maven spring-boot spring-boot-maven-plugin

5
推荐指数
1
解决办法
7621
查看次数

Spring Boot 可执行 jar 抛出 java.lang.ClassNotFoundException: org.apache.tomcat.util.descriptor.web.ServletDef

我创建了一个简单的测试用例,显示了我目前面临的问题。

我试图做的是手动启动从 CommandLineRunner 嵌入的 Tomcat 并手动部署文件系统上某处可用的 war 文件:

package example;

import java.io.File;

import org.apache.catalina.Context;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.Tomcat;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class MyCommandLineRunner implements CommandLineRunner {

    @Override
    public void run(String... args) throws Exception {

        File tomcatBaseDir = new File("<tomcat-base-dir>");
        File warToBeDeployed = new File("<war-to-be-deployed>");

        Tomcat tomcat = new Tomcat();
        tomcat.setPort(8080);
        tomcat.setBaseDir(tomcatBaseDir.getAbsolutePath());
        tomcat.getHost().setAppBase(tomcatBaseDir.getAbsolutePath());
        tomcat.getHost().setAutoDeploy(true);
        tomcat.getHost().setDeployOnStartup(true);

        try {
            tomcat.start();
            System.out.println("Tomcat started on " + tomcat.getHost());
        } catch (LifecycleException e) {
            System.err.println("Tomcat could not be started");
            System.exit(-1);
        }

        Context appContext …
Run Code Online (Sandbox Code Playgroud)

java maven spring-boot spring-boot-maven-plugin

5
推荐指数
1
解决办法
6774
查看次数

使用Maven使用requireUnpack构建的Spring Boot JAR无法正常工作

我认为我一直遇到以下问题:泽西岛不适用于Spring Boot胖罐。解决方法应该是设置泽西依赖POMrequiresUnpack

我的POM样子是这样的:

<?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>

    <groupId>net.hagstrom</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jersey</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <requiresUnpack>
                        <dependency>
                            <groupId>org.glassfish.jersey.containers</groupId>
                            <artifactId>jersey-container-servlet</artifactId>
                        </dependency>
                        <dependency>
                            <groupId>org.glassfish.jersey.core</groupId>
                            <artifactId>jersey-client</artifactId>
                        </dependency> …
Run Code Online (Sandbox Code Playgroud)

java spring maven spring-boot spring-boot-maven-plugin

5
推荐指数
1
解决办法
3168
查看次数

spring-boot-maven-plugin 的使用

在创建 Spring Boot 项目时,我在 pom.xml 中定义了属性<packaging>war</packaging>,我可以用它来创建战争,然后将战争部署到服务器中,可能是 tomcat 或 WAS。
但是我遇到了一个名为spring-boot-maven-plugin 的插件,其文档说明它的用途是打包可执行的 jar 或 war 档案并就地运行应用程序
我的疑问是为什么我们需要这个?
如果我的打包可以告诉我要创建什么然后可以部署它运行,那么这个插件有什么用。
我正在尝试理解一个新项目,所以想确保每一行都有意义

maven-plugin spring-boot spring-boot-maven-plugin

5
推荐指数
1
解决办法
4346
查看次数

升级到 Spring Boot 版本 2 后 Prometheus 无法工作

我之前可以在 Spring Boot Version 2 中使用 Prometheus,没有任何问题。将 Spring Boot 版本更新到 2.1.1 后。发布我遇到以下错误。

我将 Prometheus 版本从 0.2.0 升级到 0.6.0 但仍然遇到相同的错误。

您认为 prometheus 与 Spring Boot Version 2 不兼容吗?

问候

   Error :
   java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration.propertySourcesPlaceholderConfigurer
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:64)
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:181)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:141)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:117)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:327)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:232)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:691)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:528)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
at com.project.projectmine.Application.main(Application.java:26)
 Caused by: java.lang.IllegalStateException: Failed to introspect Class [io.prometheus.client.spring.boot.PrometheusEndpointConfiguration] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@77556fd]
at …
Run Code Online (Sandbox Code Playgroud)

spring-boot prometheus spring-boot-maven-plugin prometheus-java

5
推荐指数
1
解决办法
4750
查看次数

带有 spring-boot-maven 插件的 Spring Boot - 运行集成测试后无法重启应用服务器

我有一个 Spring Boot 应用程序,并且该应用程序具有集成测试。

这是我的 pom.xml 中用于运行集成测试的相关片段。

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
      <mainClass>com.xyz.Application</mainClass>
      <executable>true</executable>
      <fork>true</fork>
      <jmxPort>7654</jmxPort>
    </configuration>
    <executions>
      <execution>
        <id>pre-integration-test</id>
        <goals>
          <goal>start</goal>
        </goals>
        <configuration>
          <fork>true</fork>
          <jmxPort>7654</jmxPort>
        </configuration>
      </execution>
      <execution>
        <id>post-integration-test</id>
        <goals>
          <goal>stop</goal>
        </goals>
        <configuration>
          <fork>true</fork>
          <jmxPort>7654</jmxPort>
        </configuration>
      </execution>
    </executions>
  </plugin>
Run Code Online (Sandbox Code Playgroud)

当我运行时mvn verify,我看到单元测试首先运行。然后应用服务器启动,集成测试成功运行。mvn 进程成功退出。

我还在控制台日志中看到以下内容,这让我相信应用程序服务器正在正确关闭 -

[INFO] --- spring-boot-maven-plugin:2.1.1.RELEASE:stop (post-integration-test) @ application ---
[DEBUG] Configuring mojo org.springframework.boot:spring-boot-maven-plugin:2.1.1.RELEASE:stop from plugin realm ClassRealm[plugin>org.springframework.boot:spring-boot-maven-plugin:2.1.1.RELEASE, parent: sun.misc.Launcher$AppClassLoader@42a57993]
[DEBUG] Configuring mojo 'org.springframework.boot:spring-boot-maven-plugin:2.1.1.RELEASE:stop' with basic configurator -->
[DEBUG]   (f) fork = true
[DEBUG]   (f) jmxPort = …
Run Code Online (Sandbox Code Playgroud)

java jmx maven spring-boot spring-boot-maven-plugin

5
推荐指数
1
解决办法
2284
查看次数

Flyway是否支持测试文件夹下的sql迁移?

我正在将一个项目从 Spring Boot 1.5.21 迁移到 2.2.5。我已遵循指南中的所有说明。但是,我对 Flyway 有疑问(从 4.2.0 升级到 6)。

以前,当我在 下有 sql 迁移文件时src/test/resources/db/migration,flyway 会将它们作为mvn clean install命令的一部分运行。现在,由于某种原因,它停止运行这些迁移(为了澄清,我说的是maven构建而不是运行应用程序时)。

我正在使用maven 3.6.3以下flyway-maven-plugin version 6.0.8配置(某些值是与此问题无关的标记):

<plugin>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-maven-plugin</artifactId>
    <version>${flyway.version}</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>migrate</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <skip>${db.skip}</skip>
        <url>${db.url}</url>
        <user>${db.username}</user>
        <password>${db.password}</password>
        <locations>
            <location>classpath:db/migration</location>
        </locations>
        <schemas>public,downstream</schemas>
        <outOfOrder>true</outOfOrder>
        <callbacks>
            db.migration.callback.PopulateControlFieldsFlywayCallback,db.migration.callback.UpdateReplicaIdentityFlywayCallback,db.migration.callback.UpdateSchemaHistoryTableFlywayCallback
        </callbacks>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>${postgresql.version}</version>
        </dependency>
    </dependencies>
</plugin>
Run Code Online (Sandbox Code Playgroud)

为什么行为发生了变化?如何恢复旧的行为?我错过了什么吗?

maven-3 flyway spring-boot spring-boot-maven-plugin

5
推荐指数
1
解决办法
1882
查看次数

突然 spring-boot-maven-plugin:2.7.1:build-image 无法下载 spring-cloud-bindings

在 AWS CodeBuild 管道中,我在构建映像任务期间收到此错误:

could not download https://repo.spring.io/release/org/springframework/cloud/spring-cloud-bindings/1.10.0/spring-cloud-bindings-1.10.0.jar
Run Code Online (Sandbox Code Playgroud)

同样的构建在我的 PC 上失败,并且 repo.spring.io 上不再存在工件 spring-cloud-bindings-1.10.0.jar。

spring-boot spring-boot-maven-plugin

5
推荐指数
1
解决办法
600
查看次数