Java Spring Boot Maven集成测试给出ClassNotFoundException

Java Spring Boot Maven集成测试给出ClassNotFoundException,java,maven,spring-boot,soap,junit,Java,Maven,Spring Boot,Soap,Junit,我有一个SpringBoot项目,有两个应用程序,一个在src/test中,一个在src/main中。我有两个应用程序,一个用于连接SOAP端点的中介程序,另一个用作模拟服务器进行测试 我有一个集成测试,检查它是否会命中(需要测试应用程序(端口9119)和主应用程序(端口28433)启动) 我使用maven spring启动插件在我的POM中配置运行这两个应用程序,并在运行mvn验证时使其跳过单元测试 <plugin> <groupId>org.s

我有一个SpringBoot项目,有两个应用程序,一个在src/test中,一个在src/main中。我有两个应用程序,一个用于连接SOAP端点的中介程序,另一个用作模拟服务器进行测试

我有一个集成测试,检查它是否会命中(需要测试应用程序(端口9119)和主应用程序(端口28433)启动)

我使用maven spring启动插件在我的POM中配置运行这两个应用程序,并在运行mvn验证时使其跳过单元测试

<plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
             <includePom>true</includePom>          
        </configuration>  
            <executions>
                <execution>
                    <id>pre-integration-test</id>
                    <goals>
                        <goal>start</goal>
                    </goals>
                    <configuration>
               <mainClass>com.nulogix.billing.App</mainClass>   
                    </configuration> 

                </execution>
                <execution>
                    <id>pre-integration-test2</id>
                    <goals>
                        <goal>start</goal>
                    </goals>
                    <configuration>
               <mainClass>com.nulogix.billing.mockserver.MockServerApp</mainClass>   
                    </configuration> 

                </execution>
                <execution>
                    <id>post-integration-test</id>
                    <goals>

                         <goal>stop</goal>                  
                    </goals>
                     <configuration>
               <mainClass>com.nulogix.billing.App</mainClass>   
                    </configuration>

                </execution>
                <execution>
                    <id>post-integration-test2</id>
                    <goals>

                         <goal>stop</goal>                  
                    </goals>
                     <configuration>
               <mainClass>com.nulogix.billing.mockserver.MockServerApp</mainClass>   
                    </configuration>

                </execution>
            </executions>

        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.18.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M3</version>
    <configuration>
        <skipTests>true</skipTests>
    </configuration>
</plugin>
类路径目录是正确的。我尝试在我的pom中添加一个类作用域,但它似乎无法解决问题,并给了我相同的错误

在后集成阶段,当它关闭时,会出现这个错误,我认为这只是意味着它无法加载应用程序上下文,因此没有找到关闭它的bean

Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.0.RELEASE:stop (post-integration-test2) on project billing_mediator: Spring application lifecycle JMX bean not found (fork is null). Could not stop application gracefully: org.springframework.boot:type=Admin,name=SpringApplication -> [Help 1]
当我为堆栈跟踪运行mvn-x时,它会自动给我一个构建失败,并给我这个错误

org.apache.maven.lifecycle.NoGoalSpecifiedException: No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy.
org.apache.maven.lifecycle.nogoalsspecifiedException:尚未为此构建指定任何目标。必须以以下格式指定有效的生命周期阶段或目标:或:[:]:。可用的生命周期阶段包括:验证、初始化、生成源、流程源、生成资源、流程资源、编译、流程类、生成测试源、流程测试源、生成测试资源、流程测试资源、测试编译、流程测试类、测试、准备包、包、预集成测试、,集成测试、集成后测试、验证、安装、部署、预清理、清理、清理后、预站点、站点、站点后、站点部署。

这是否意味着我的POM设置有误?

我之所以能做到这一点,是因为maven没有扫描src/test文件夹,所以我只在主应用程序中添加了一个集成阶段。然后,我创建了模拟服务器的应用程序上下文,并使其在测试类之前运行

<plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
            <mainClass>com.nulogix.billing.App</mainClass> 
        </configuration>
            <executions>
                <execution>
                    <id>pre-integration-test</id>
                    <goals>
                        <goal>start</goal>
                    </goals>
                </execution>
                <execution>
                    <id>post-integration-test</id>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>

        </plugin>

这将使我的主应用程序运行预集成测试,然后在测试运行之前启动我的mockserver应用程序。因此,这将在集成测试之前启动这两个应用程序,并点击我的soap调用

如果只保留一对启动/停止开关,可以吗?例如,仅对于
com.nulogix.billing.mockserver.MockServerApp
@QingfeiYuan,我还需要运行我的主应用程序,以便在集成测试时成功连接到soap端点。我知道这一点。只是想知道这是否是根本原因。如果是的话,我们可以有其他的解决办法。@QingfeiYuan啊,好的,那么是的。它在28433上成功启动,只有那个端口处于集成阶段。如果这个插件确认只允许一对启动/停止。然后你有两个合并2开始变成1。同样的,我也要停下来。我想。
<plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
            <mainClass>com.nulogix.billing.App</mainClass> 
        </configuration>
            <executions>
                <execution>
                    <id>pre-integration-test</id>
                    <goals>
                        <goal>start</goal>
                    </goals>
                </execution>
                <execution>
                    <id>post-integration-test</id>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>

        </plugin>
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {EndPointTestConfiguration.class
})


public class SoapIT {
private static ApplicationContext context;
    @BeforeClass
    static public void  setup(){
        SpringApplication springApplication = new SpringApplicationBuilder()           
                .sources(MockServerApp.class)
                .build();
        context = springApplication.run();
    }


    @Autowired
    private String studyDetailDemo;
    @Test
    public void soapTest() throws ClientProtocolException, IOException {
        String result = Request.Post("https://127.0.0.1:28433/nulogix/ws/billingtool")
                .connectTimeout(2000)
                .socketTimeout(2000)
                .bodyString("testing", ContentType.TEXT_PLAIN)
                .execute().returnContent().asString();

    }
}