如何在不包括基于maven的Springboot应用程序中应用程序中现有的主类的情况下单独运行命令行主类



我面临着奇怪的情况。当我运行现有的主应用程序时,它在运行时还包括另一个commandLine主类。

我在pom.xml-中创建了2个配置文件,还设置了mainClass标记。1-单元测试2-集成测试

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
    <mainClass>${commandLineMainClass}</mainClass>
</configuration>
</plugin>

在集成测试中,我使用命令行运行程序创建了单独的主类,只需点击即可测试部署在另一台服务器上的应用程序。

我有两个问题-

1-当我运行现有的主类应用程序时,它也使用命令行主类启动。在命令行未手动运行之前,应将其排除在外。

  1. 当我运行命令行主类时,我无法访问自定义的应用程序-{env}.properties,尽管它不包括现有的<strong]应用程序主类>,这很好

我也在使用springBootmaven插件。请帮忙。

<project>
<parent>
    <groupid>org.springframework.boot</groupid>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.1.RELEASE</version>
    <relativePath/>
</parent>
<properties>
    <java.version>1.8</java.version>
    <start-class>thisisCommandLineProp</start-class>
    <environment>thisisCommandLineProp</environment>
</properties>
<profiles>
    <profile>
        <id>unittest</id>
        <build>
            <filename>${project.artifactId}</filename>
        </build>
    </profile>
    <profile>
        <id>integrationtest</id>
        <build>
            <filename>${project.artifactId}</filename>
            <plugins>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <skipTests>true</skipTests>
                    </configuration>
                </plugin>
                <plugin>
                    <groupid>org.springframework.boot</groupid>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <configuration>
                                <workingDirectory>${project.basedir}srcintegration-test</workingDirectory>
                                <mainClass>${project.basedir}srcintegration-test${start-class}</mainClass>
                                <arguments>
                                    <argument>
                        spring.config.location=${project.basedir}srcmainresourcesapplication-${environment}.properties</argument>
                                </arguments>
                            </configuration>
                            <goals>
                                <goal>run</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>
<project>

**命令-**spring-boot:run-Denvironment=dev-Dstart class=com.abc.xyz.Integrationtest-Pinttegrationtest

相关内容

最新更新