# Spring 项目进行测试的时候提示 @SpringBootConfiguration 没有配置

**URL:** <https://www.isharkfly.com/t/spring-springbootconfiguration/14073>\
**Category:** 程序语言\
**Tags:** java, spring\
**Created:** [August 25, 2022, 8:29pm UTC](https://www.isharkfly.com/t/spring-springbootconfiguration/14073 "2022-08-25T20:29:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [August 25, 2022, 8:29pm UTC](https://www.isharkfly.com/t/spring-springbootconfiguration/14073/1 "2022-08-25T20:29:01Z")

</div>

提示的配置信息为：

```auto
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test

	at org.springframework.util.Assert.state(Assert.java:76)
	at org.springframework.boot.test.context.SpringBootTestContextBootstrapper.getOrFindConfigurationClasses(SpringBootTestContextBootstrapper.java:236)
	at org.springframework.boot.test.context.SpringBootTestContextBootstrapper.processMergedContextConfiguration(SpringBootTestContextBootstrapper.java:152)
	at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildMergedContextConfiguration(AbstractTestContextBootstrapper.java:393)
	at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildDefaultMergedContextConfiguration(AbstractTestContextBootstrapper.java:309)
	at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildMergedContextConfiguration(AbstractTestContextBootstrapper.java:262)
	at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildTestContext(AbstractTestContextBootstrapper.java:107)

```

 ![2022-08-25_16-25-34](https://cdn.isharkfly.com/com-isharkfly-www/discourse-uploads/original/2X/c/c5f67c5ea581aa2c12f50ad90bd0a216022cc35b.png)

看提示上说的是没有找到配置属性。

## 问题和解决

如果我们确定已经配置了 Spring ，但是测试没有办法测试的话，主要原因是启动文件和测试文件的包不在一个路径下。

针对我们的项目，我们 Application 的路径在：

`package com.usvisatrack.data;`

但是我们这个测试文件的路径在：

`package com.usvisatrack.service;`

这样的配置是没有办法让测试运行的。

解决办法就是将路径调整下，将这个测试文件放到：

`package com.usvisatrack.data.tests;`

路径下就可以了。

 ![2022-08-25_16-28-37](https://cdn.isharkfly.com/com-isharkfly-www/discourse-uploads/original/2X/5/5f1f270e07573cafded676e56b303734edfee3c9.png)

如上图更新后的显示。
