当前位置: 首页 > 知识库问答 >
问题:

Spring启动没有maven父和unittest不运行

郤玉书
2023-03-14

我尝试在样例中修改spel-boot-samples-集成项目的Maven构建,以不使用父spel-boot-starter-父,而是在依赖管理中导入spel-boot-依赖项pom。这是因为我想在现有项目中使用Spring Boot作为Maven模块。

所有构建都可以;但是,jUnit测试不在Maven安装生命周期上运行。我想知道我还需要做什么,为什么会有不同。下面是我使用的pom。我没有修改任何示例类。我只是修改了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>
    <artifactId>spring-boot-samples</artifactId>
    <version>1.0-SNAPSHOT</version>
    <groupId>org.springframework.boot</groupId>

    <properties>
        <main.basedir>${basedir}</main.basedir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <url>http://repo.spring.io/snapshot</url>
            <snapshots><enabled>true</enabled></snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <url>http://repo.spring.io/milestone</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <url>http://repo.spring.io/snapshot</url>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <url>http://repo.spring.io/milestone</url>
        </pluginRepository>
        <pluginRepository>
            <id>Central</id>
            <url>http://repo1.maven.org/maven2</url>
        </pluginRepository>
    </pluginRepositories>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>1.2.0.BUILD-SNAPSHOT</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-integration</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
       <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-jmx</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-ip</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-xml</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-autoconfigure</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-surefire-plugin</artifactId>
                <version>2.17</version>
                <configuration>
                    <argLine>-XX:MaxPermSize=128m -Xmx256m</argLine>
                    <forkCount>1</forkCount>
                    <reuseForks>false</reuseForks>
                    <runOrder>alphabetical</runOrder>
                    <argLine>-Dfile.encoding=${project.build.sourceEncoding}</argLine>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>1.2.0.BUILD-SNAPSHOT</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

共有1个答案

璩涛
2023-03-14

我们的惯例是以Tests结束测试,而不是test,因此您需要向maven surefire插件说明我们的默认设置。

像这样的东西

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <includes>
      <include>**/*Tests.java</include>
    </includes>
    <excludes>
      <exclude>**/Abstract*.java</exclude>
    </excludes>
  </configuration>
</plugin>
 类似资料:
  • 我目前正在开发一个部署在heroku中的Spring Boot应用程序。该应用程序在同一回购协议上有两个主要项目(前端和后端)。我设法用node运行了前端。js和(技术上)也成功地运行了spring boot应用程序。 根据日志,一切似乎都正常,但当我访问应用程序时,它返回一个HTTP 500,声称没有运行Web进程。 但当我和heroku ps联系时 这是我的文件: 它声明两个进程(一个用于前端

  • 问题内容: 我一直在研究Spring / Spring MVC应用程序,并且希望添加性能指标。我遇到过Spring Boot Actuator,它看起来是一个不错的解决方案。但是我的应用程序不是Spring Boot应用程序。我的应用程序在传统容器Tomcat 8中运行。 我添加了以下依赖 我创建了以下配置类。 我什至可以按照StackOverflow另一篇文章的建议在每个配置类上添加 问题答案:

  • 我有一个Maven多模块项目,在主pom中将一些旧版本的Spring Boot依赖项设置为父项。xml。所有子模块都从这个主pom继承Spring Boot依赖项。xml。 这很好,但是在一个新的子模块(也是多模块)中,我想使用最新的Spring引导版本,而不改变项目中正在使用的版本(以及所有依赖项)。 有没有办法巧妙地覆盖从父版本派生的Spring引导版本(及其所有依赖项),并在子模块中使用不同

  • 无法使用maven运行spring启动应用程序。当我运行命令mvn spring boot:run时,我收到:,但在pom中。我写的xml,其中是使用该示例的主要类: 我有这个项目结构: 我希望使用spring boot和maven运行我的应用程序。但现在它不起作用了。

  • 项目Spring引导1..5.7版本。我正在使用Intellij IDEA 2017.2.4和gradle进行依赖性管理。当我构建项目时,它成功构建,没有错误。当我用bootRun gradle任务运行应用程序时,它显示以下错误。

  • 我已经从这里安装了一个Android Studio。它起作用了,我写了一个hello world项目,然后关闭了它。但IDE不会第二次启动。它会给我一个错误“缓存被锁定”。 我安装了unlocker,它说没有进程阻止这个文件夹。有人知道问题出在哪里吗?提前道谢。