6

我已经浏览了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

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

@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")

它给出了错误

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

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

4

1 回答 1

0

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

于 2018-05-12T09:01:32.353 回答