我已经浏览了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 文件也运行良好。我不确定在测试时有什么问题。