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

Wesley13
• 阅读 3794

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

[INFO] Scanning for projects...
[INFO] 
[INFO] -----------------------< com.swyx:swyx_form_api >-----------------------
[INFO] Building swyx_form_api 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ swyx_form_api ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ swyx_form_api ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ swyx_form_api ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory H:\swyx\codes\swyx_form\swyx_form_api\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ swyx_form_api ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ swyx_form_api ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
06:53:52.377 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class com.swyx.tools.SwyxFormApplicationTests]
06:53:52.384 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
06: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)]
06: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]
06: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
06: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
06: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
06: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}.
06: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.
06: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]
06:53:52.957 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class com.swyx.tools.SwyxFormApplicationTests]
06:53:52.958 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
06: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)]
06: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]
06: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
06: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
06: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
06: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}.
06: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.
06: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]
[INFO] Running com.swyx.tools.SwyxFormApplicationTests
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.02 s <<< FAILURE! - in com.swyx.tools.SwyxFormApplicationTests
[ERROR] initializationError  Time elapsed: 0.001 s  <<< ERROR!
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test

[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Errors: 
[ERROR]   SwyxFormApplicationTests ? IllegalState Unable to find a @SpringBootConfigurat...
[INFO] 
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  8.412 s
[INFO] Finished at: 2019-06-04T06:53:53+08:00
[INFO] ------------------------------------------------------------------------
[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.
[ERROR] 
[ERROR] Please refer to H:\swyx\codes\swyx_form\swyx_form_api\target\surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

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

现有的test启动类:

@RunWith(SpringRunner.class)
@SpringBootTest
public class SwyxFormApplicationTests {

    @Test
    public void contextLoads() {
    }

}

修改后test启动类:

@RunWith(SpringRunner.class)
@SpringBootTest
@ContextConfiguration(classes = SwyxFormApplication.class)
public class SwyxFormApplicationTests {

    @Test
    public void contextLoads() {
    }

}

@RunWith(SpringRunner.class)
@SpringBootTest(classes = SwyxFormApplication.class)
public class SwyxFormApplicationTests {

    @Test
    public void contextLoads() {
    }

}
点赞
收藏
评论区
推荐文章
blmius blmius
2年前
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
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
blmius blmius
2年前
linux find 命令查找文件和文件夹
查找目录:find/(查找范围)name'查找关键字'typed查找文件:find/(查找范围)name查找关键字print详解:find命令用来在指定目录下查找文件。任何位于参数之前的字符串都将被视为欲查找的目录名。如果使用该命令时,不设置任何参数,则find命令将在当前目录下查找子目录与文件。并且将查找到的子目录和文件全部进行显示。
红烧土豆泥 红烧土豆泥
2年前
Spring Boot:jar中没有主清单属性
使用SpringBoot微服务搭建框架时,使用IDEA可以正常运行,但是使用MAVEN打包工具打包成jar后运行时,提示错误:未找到主清单目录。查看pom文件,发现已添加SpringBoot的构建插件xmlorg.springframework.bootspringbootmavenplugin2.4.1
Easter79 Easter79
2年前
Vue+Webpack配置css
  使用VueWebpack搭建工程时,在webpack.config.js中的module的rules里针对各种文件配置加载工具。在针对css文件配置时遇到一个问题:打包构建时报错——Modulebuildfailed:Unknownword。  配置内容如下:{  test:/\.css$/,  use:
Stella981 Stella981
2年前
Python+Selenium自动化篇
本篇文字主要学习selenium定位页面元素的集中方法,以百度首页为例子。0.元素定位方法主要有:id定位:find\_element\_by\_id('')name定位:find\_element\_by\_name('')class定位:find\_element\_by\_class\_name(''
Stella981 Stella981
2年前
Linux中递归更改文件扩展名的命令
比如我需要将jpg结尾的图片文件修改为png结尾的如果能用rename命令,运行下面的find.name'.jpg'execrename.jpg.png{}如果不能用rename命令,使用下面的find.name".jpg"execbashc'mv"$1"
Wesley13 Wesley13
2年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
4个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这
程昱 程昱
2个月前
2023最新版-Web前端架构师35周完结无密
2023最新版Web前端架构师35周完结无密download》quangneng.com/3677/Web前端工程师需要学什么Web前端工程师需要学习的技能和知识主要包括以下几个方面:HTML/CSS/JavaScript:HTML、CSS和JavaScr