我可以在src / test / java中创建SpringBootApplication吗?

时间:2019-01-24 15:43:12

标签: java spring spring-boot

我们想在Docker中运行一些远程测试。我们的想法是创建一个SpringBootApplication来运行测试并报告结果,然后将此应用程序部署在自己的Docker和自己的JAR中。

为确保它不随主要代码(src / main / java)一起提供,我们希望将此代码包含在src / test / java中。.

在文档中,Spring-boot-maven-plugin似乎无法实现。

所以现在我试图创建一个测试罐,但是当我运行Application类时,我得到了

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

2019-01-24 10:38:56.736  INFO 5082 --- [           main] c.h.i.smoketest.SmokeTestApplication     : Starting SmokeTestApplication on 1usmfkelly.ad.here.com with PID 5082 (/usr/local/aaa/identity-client/target/identity-client-0.1.0-SNAPSHOT-tests.jar started by fkelly in /usr/local/aaa/identity-client/target)
2019-01-24 10:38:56.738  INFO 5082 --- [           main] c.h.i.smoketest.SmokeTestApplication     : No active profile set, falling back to default profiles: default
2019-01-24 10:38:56.777  INFO 5082 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@3aeaafa6: startup date [Thu Jan 24 10:38:56 EST 2019]; root of context hierarchy
2019-01-24 10:38:56.852  WARN 5082 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.here.identity.smoketest.SmokeTestApplication]; nested exception is java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.
2019-01-24 10:38:56.860 ERROR 5082 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.here.identity.smoketest.SmokeTestApplication]; nested exception is java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.
    at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:558) ~[identity-client-0.1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:187) ~[identity-client-0.1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:308) ~[identity-client-0.1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:228) ~[identity-client-0.1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:272) ~[identity-client-0.1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:92) ~[identity-client-0.1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687) ~[identity-client-0.1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525) ~[identity-client-0.1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[identity-client-0.1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [identity-client-0.1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [identity-client-0.1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [identity-client-0.1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [identity-client-0.1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [identity-client-0.1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at com.here.identity.smoketest.SmokeTestApplication.main(SmokeTestApplication.java:12) [identity-client-0.1.0-SNAPSHOT-tests.jar:na]
Caused by: java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.
    at org.springframework.util.Assert.notEmpty(Assert.java:277) ~[identity-client-0.1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getCandidateConfigurations(AutoConfigurationImportSelector.java:153) ~[identity-client-0.1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.selectImports(AutoConfigurationImportSelector.java:95) ~[identity-client-0.1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:549) ~[identity-client-0.1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    ... 14 common frames omitted

有没有关于如何在没有maven插件的情况下打包SpringBoot应用程序的文档?

1 个答案:

答案 0 :(得分:0)

事实证明,向源存储库添加文件所需要做的一切

src/main/resources/META-INF/spring.factories

您可以从here

获取副本

非常感谢另一篇有关该问题的answer