在Spring boot中:找不到模板位置:类路径资源[模板/](请添加一些模板或检查您的Thymeleaf配置)

Mas*_*ode 6 spring-mvc-test spring-boot

我已经浏览了https://github.com/spring-projects/spring-boot/issues/424但我的项目结构在 /templates 目录中包含 .html 文件,如下所示

.

|-- java
| `-- com
|       `-- projectx
|           |-- config
|           |   |-- Application.java
|           |   `-- WebXmlInitialiser.java
|           |-- controller
|           |   `-- CustomerQuickRegisterController.java
|           |-- domain
|           |   `-- Email.java
|           `-- services
|               |-- CustomerQuickRegisterDataFixtures.java
|               |-- CustomerQuickRegisterHandler.java
|               `-- CustomerQuickRegisterService.java
`-- resources
    |-- application.properties
    `-- templates
        |-- emailForm.html
        `-- result.html
Run Code Online (Sandbox Code Playgroud)

但是仍然在使用以下测试进行测试时

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
@IntegrationTest

@ActiveProfiles("Test")
public class CustomerQuickRegisterControllerIntergrationTest {


    @Autowired
    private WebApplicationContext  wac;

    MockMvc mockMvc;

    @Before
    public void setUp()
    {
        this.mockMvc=MockMvcBuilders.webAppContextSetup(wac).build();
    }

    @Test
    public void thatEmailAddedSucessfully() throws Exception {

        this.mockMvc.perform(
                post("/email/addemail")
Run Code Online (Sandbox Code Playgroud)

它给出的错误是

java.lang.IllegalStateException: Cannot find template location: class path resource [templates/] (please add some templates or check your Thymeleaf configuration) 
Run Code Online (Sandbox Code Playgroud)

但是当我将这个项目作为 gradle 运行时,build:bootRun它运行良好。此外,从该项目创建的 .war 文件运行良好。我不确定在测试时有什么问题。

Mas*_*ode 0

我检查了一下,IDE有问题。现在它工作正常。最初我很困惑,因为它gradle:bootRun工作正常并且我能够访问这些视图 HTML 文件。