为Maven预集成测试阶段启动多个Spring Boot应用程序

时间:2019-08-21 13:22:22

标签: java maven spring-boot integration-testing lifecycle

我有两个Spring Boot应用程序,一个包含在我的src / test中,一个包含在我的src / main中。

我正在使用Maven验证来运行SOAP集成测试。我已经成功启动了我的主应用程序,但也想启动我的测试应用程序的预集成。我想在测试应用程序上运行测试,然后还需要打开主应用程序,以便它可以连接到SOAP端点。

当我运行mvn verify时,它将在集成前启动我的主应用程序,然后仅运行集成测试。是否可以启动另一个应用程序?如果是,如何将其配置到我的maven-springboot-plugin中?

[INFO] --- spring-boot-maven-plugin:2.1.0.RELEASE:start (pre-integration-test) @ billing_mediator ---

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.0.RELEASE)

2019-08-21 09:20:41.577  INFO 53762 --- [ling.App.main()] com.nulogix.billing.App                  : Starting App on Alexs-MacBook-Pro.local with PID 53762 (/Users/Alex/Documents/billing/billing_mediator/target/classes started by asluborski in /Users/asluborski/Documents/billing/billing_mediator)
2019-08-21 09:20:41.582 DEBUG 53762 --- [ling.App.main()] com.nulogix.billing.App                  : Running with Spring Boot v2.1.0.RELEASE, Spring v5.1.2.RELEASE
2019-08-21 09:20:41.585  INFO 53762 --- [ling.App.main()] com.nulogix.billing.App                  : No active profile set, falling back to default profiles: default
2019-08-21 09:20:42.541  INFO 53762 --- [ling.App.main()] trationDelegate$BeanPostProcessorChecker : Bean 'webServiceConfig' of type [com.nulogix.billing.ws.endpoint.WebServiceConfig$$EnhancerBySpringCGLIB$$ad324219] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-08-21 09:20:42.544  INFO 53762 --- [ling.App.main()] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.ws.config.annotation.DelegatingWsConfiguration' of type [org.springframework.ws.config.annotation.DelegatingWsConfiguration$$EnhancerBySpringCGLIB$$668ea787] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-08-21 09:20:42.593  INFO 53762 --- [ling.App.main()] .w.s.a.s.AnnotationActionEndpointMapping : Supporting [WS-Addressing August 2004, WS-Addressing 1.0]
2019-08-21 09:20:43.099  INFO 53762 --- [ling.App.main()] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 28443 (https)
2019-08-21 09:20:43.128  INFO 53762 --- [ling.App.main()] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-08-21 09:20:43.129  INFO 53762 --- [ling.App.main()] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/9.0.12
2019-08-21 09:20:43.144  INFO 53762 --- [ling.App.main()] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/Users/asluborski/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.]
2019-08-21 09:20:43.258  INFO 53762 --- [ling.App.main()] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-08-21 09:20:43.258  INFO 53762 --- [ling.App.main()] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1625 ms
2019-08-21 09:20:43.300  INFO 53762 --- [ling.App.main()] o.s.b.w.servlet.ServletRegistrationBean  : Servlet messageDispatcherServlet mapped to [/nulogix/ws/*]
2019-08-21 09:20:43.302  INFO 53762 --- [ling.App.main()] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2019-08-21 09:20:43.307  INFO 53762 --- [ling.App.main()] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2019-08-21 09:20:43.308  INFO 53762 --- [ling.App.main()] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2019-08-21 09:20:43.308  INFO 53762 --- [ling.App.main()] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'formContentFilter' to: [/*]
2019-08-21 09:20:43.308  INFO 53762 --- [ling.App.main()] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2019-08-21 09:20:43.350 DEBUG 53762 --- [ling.App.main()] c.n.b.service.PredictionEngineService    : billing.engine.address=127.0.0.1
2019-08-21 09:20:43.351 DEBUG 53762 --- [ling.App.main()] c.n.b.service.PredictionEngineService    : billing.engine.port=9119
2019-08-21 09:20:43.351 DEBUG 53762 --- [ling.App.main()] c.n.b.service.PredictionEngineService    : Using http://127.0.0.1:9119
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.sun.xml.bind.v2.runtime.reflect.opt.Injector (file:/Users/asluborski/.m2/repository/com/sun/xml/bind/jaxb-impl/2.2.11/jaxb-impl-2.2.11.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
WARNING: Please consider reporting this to the maintainers of com.sun.xml.bind.v2.runtime.reflect.opt.Injector
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2019-08-21 09:20:43.847 DEBUG 53762 --- [ling.App.main()] c.n.billing.ws.endpoint.AnalyzeEndPoint  : billing.engine.api.version=0.97
2019-08-21 09:20:43.847 DEBUG 53762 --- [ling.App.main()] c.n.billing.ws.endpoint.AnalyzeEndPoint  : billing.engine.core.version=0.97
2019-08-21 09:20:43.848 DEBUG 53762 --- [ling.App.main()] c.n.billing.ws.endpoint.AnalyzeEndPoint  : billing.engine.core.name=Nulogix_Patient_Responsibility
2019-08-21 09:20:43.851 DEBUG 53762 --- [ling.App.main()] c.n.b.ws.endpoint.GetVersionEndPoint     : billing.engine.api.version=0.97
2019-08-21 09:20:44.099  INFO 53762 --- [ling.App.main()] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-08-21 09:20:45.055  INFO 53762 --- [ling.App.main()] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 28443 (https) with context path ''
2019-08-21 09:20:45.060  INFO 53762 --- [ling.App.main()] com.nulogix.billing.App                  : Started App in 4.044 seconds (JVM running for 13.722)
[INFO] 
[INFO] --- maven-failsafe-plugin:2.18.1:integration-test (default) @ billing_mediator ---

编辑:

所以我编辑了POM并添加了多个这样的执行程序(不确定这是否正确,找不到有关如何为spring boot maven插件执行此操作的文档)

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

这在尝试启动测试服务器(MockServerApp)时给了我一个错误。

java.lang.ClassNotFoundException: com.nulogix.billing.mockserver.MockServerApp
    at java.net.URLClassLoader.findClass (URLClassLoader.java:436)
    at java.lang.ClassLoader.loadClass (ClassLoader.java:588)
    at java.lang.ClassLoader.loadClass (ClassLoader.java:521)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run (AbstractRunMojo.java:553)
    at java.lang.Thread.run (Thread.java:835)

不知道为什么会给我这个错误,因为它是正确的类路径,并且该类存在于src / test / java下

编辑:

我将此添加到插件的配置中

<plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
             <includePom>true</includePom>      
             <additionalClasspathElements>
            <additionalClasspathElement>${basedir}/target/test-classes</additionalClasspathElement>
        </additionalClasspathElements>    
        </configuration>  

但是我遇到同样的错误。

添加classpathscope也无法解决:

<execution>
                    <id>pre-integration-test2</id>
                    <goals>
                        <goal>start</goal>
                    </goals>
                    <configuration>

               <mainClass>com.nulogix.billing.mockserver.MockServerApp</mainClass> 
              <classpathScope>test</classpathScope>
                    </configuration>                                      
                </execution>

0 个答案:

没有答案
相关问题