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

我可以用src/test/java创建一个SpringBootApplication吗?

商焕
2023-03-14

从文档中可以看出,这在spring-boot-maven-plugin中是不可能的。

所以现在我正在尝试创建一个测试JAR,但是当我运行应用程序类时,我得到了

      .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: 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个答案

公冶森
2023-03-14

原来我所需要做的只是添加一个文件到我的源repo

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

你可以从这里拿到一份

这一切都要感谢另一篇与这个问题相关的帖子的回答

 类似资料:
  • 我想创建一个简单的Java类文件,并从我的所有项目访问它。 我知道我可以通过复制/粘贴方法来完成,但在这种情况下,类文件将独立于其原始源。我在原始类文件中所做的任何更改都不会影响已经复制到其他项目中的类文件。 在Android Studio中有链接类文件的方法吗?

  • 我正在使用JPA QueryDSL从DB查询数据,这很管用。现在,我有一个用JPA QueryDSL编写的复杂的select查询,我需要使用它创建一个临时表,如下所示(POSTGRES)。 有没有人可以帮助使用JPA QueryDSL定义上面的查询。有可能用JPA查询处理DDL吗? 您对我的问题提出的建议将不胜感激。

  • 可以用JAVA创建一个对象,然后立即在同一行上使用setter吗? 如下所示:。设置某物(“字符串”); 我如何才能正确地执行此操作,eclipse总是说: 类型不匹配:无法从空转换到类类型

  • 无法使用maven pom和eclipse目标一致地创建src/test/java模块jar 这是我的pom文件:当我通过runconfig使用eclipse运行时-- 如果我运行compile assembly:single-in-goals,它会创建SFDCSearchSuite-0.0.1-SNAPSHOT-jar-with-dependencies。每次使用所有src/main/java类

  • 我想将用户输入存储到ArrayList中,然后将该ArrayList放入另一个ArrayList中。这有点像一个主类别,它包含包含数据的子类别。 以下是一些代码: 我可以在"main Cat"ArrayList中添加"subCat"ArrayList吗?

  • 嗨,我只是想知道有没有可能创建一个通用类来确认ObserveObject协议,它可以被多个ContentView使用。 如果我能做到这一点,那么我将能够使我的ContentView和Model类完全通用和可重用。 我希望实现的一个例子: 如果我能做到这一点,任何类都可以实现ContentViewModelType,并成为ContentView的模型,使其通用且可重用。举个例子 但是当我尝试初始化C