Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTe...

SpringBoot Maven工程打包时(执行run as maven install命令),报以下错误:

1[INFO] Scanning for projects... 2[INFO] 3[INFO] -----------------------< com.swyx:swyx_form_api >----------------------- 4[INFO] Building swyx_form_api 0.0.1-SNAPSHOT 5[INFO] --------------------------------[ jar ]--------------------------------- 6[INFO] 7[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ swyx_form_api --- 8[INFO] Using 'UTF-8' encoding to copy filtered resources. 9[INFO] Copying 1 resource 10[INFO] Copying 1 resource 11[INFO] 12[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ swyx_form_api --- 13[INFO] Nothing to compile - all classes are up to date 14[INFO] 15[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ swyx_form_api --- 16[INFO] Using 'UTF-8' encoding to copy filtered resources. 17[INFO] skip non existing resourceDirectory H:\swyx\codes\swyx_form\swyx_form_api\src\test\resources 18[INFO] 19[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ swyx_form_api --- 20[INFO] Nothing to compile - all classes are up to date 21[INFO] 22[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ swyx_form_api --- 23[INFO] 24[INFO] ------------------------------------------------------- 25[INFO] T E S T S 26[INFO] ------------------------------------------------------- 2706:53:52.377 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class com.swyx.tools.SwyxFormApplicationTests] 2806:53:52.384 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate] 2906:53:52.399 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)] 3006:53:52.469 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.swyx.tools.SwyxFormApplicationTests] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper] 3106:53:52.505 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.swyx.tools.SwyxFormApplicationTests], using SpringBootContextLoader 3206:53:52.512 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.swyx.tools.SwyxFormApplicationTests]: class path resource [com/swyx/tools/SwyxFormApplicationTests-context.xml] does not exist 3306:53:52.513 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.swyx.tools.SwyxFormApplicationTests]: class path resource [com/swyx/tools/SwyxFormApplicationTestsContext.groovy] does not exist 3406:53:52.514 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.swyx.tools.SwyxFormApplicationTests]: no resource found for suffixes {-context.xml, Context.groovy}. 3506:53:52.515 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.swyx.tools.SwyxFormApplicationTests]: SwyxFormApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration. 3606:53:52.602 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.swyx.tools.SwyxFormApplicationTests] 3706:53:52.957 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class com.swyx.tools.SwyxFormApplicationTests] 3806:53:52.958 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate] 3906:53:52.958 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)] 4006:53:52.960 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.swyx.tools.SwyxFormApplicationTests] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper] 4106:53:52.962 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.swyx.tools.SwyxFormApplicationTests], using SpringBootContextLoader 4206:53:52.963 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.swyx.tools.SwyxFormApplicationTests]: class path resource [com/swyx/tools/SwyxFormApplicationTests-context.xml] does not exist 4306:53:52.964 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.swyx.tools.SwyxFormApplicationTests]: class path resource [com/swyx/tools/SwyxFormApplicationTestsContext.groovy] does not exist 4406:53:52.965 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.swyx.tools.SwyxFormApplicationTests]: no resource found for suffixes {-context.xml, Context.groovy}. 4506:53:52.966 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.swyx.tools.SwyxFormApplicationTests]: SwyxFormApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration. 4606:53:52.970 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.swyx.tools.SwyxFormApplicationTests] 47[INFO] Running com.swyx.tools.SwyxFormApplicationTests 48[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.02 s <<< FAILURE! - in com.swyx.tools.SwyxFormApplicationTests 49[ERROR] initializationError Time elapsed: 0.001 s <<< ERROR! 50java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test 51 52[INFO] 53[INFO] Results: 54[INFO] 55[ERROR] Errors: 56[ERROR] SwyxFormApplicationTests ? IllegalState Unable to find a @SpringBootConfigurat... 57[INFO] 58[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0 59[INFO] 60[INFO] ------------------------------------------------------------------------ 61[INFO] BUILD FAILURE 62[INFO] ------------------------------------------------------------------------ 63[INFO] Total time: 8.412 s 64[INFO] Finished at: 2019-06-04T06:53:53+08:00 65[INFO] ------------------------------------------------------------------------ 66[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project swyx_form_api: There are test failures. 67[ERROR] 68[ERROR] Please refer to H:\swyx\codes\swyx_form\swyx_form_api\target\surefire-reports for the individual test results. 69[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream. 70[ERROR] -> [Help 1] 71[ERROR] 72[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 73[ERROR] Re-run Maven using the -X switch to enable full debug logging. 74[ERROR] 75[ERROR] For more information about the errors and possible solutions, please read the following articles: 76[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

意为在test类中指定启动类配置

现有的test启动类:

1@RunWith(SpringRunner.class) 2@SpringBootTest 3public class SwyxFormApplicationTests { 4 5 @Test 6 public void contextLoads() { 7 } 8 9}

修改后test启动类:

1@RunWith(SpringRunner.class) 2@SpringBootTest 3@ContextConfiguration(classes = SwyxFormApplication.class) 4public class SwyxFormApplicationTests { 5 6 @Test 7 public void contextLoads() { 8 } 9 10}

1@RunWith(SpringRunner.class) 2@SpringBootTest(classes = SwyxFormApplication.class) 3public class SwyxFormApplicationTests { 4 5 @Test 6 public void contextLoads() { 7 } 8 9}
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

Vue+Webpack配置css

  使用VueWebpack搭建工程时,在webpack.config.js中的module的rules里针对各种文件配置加载工具。在针对css文件配置时遇到一个问题:打包构建时报错——Modulebuildfailed:Unknownword。  配置内容如下:{  test:/\.css$/,  use: