我已经经历了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)
但当我以build:bootRun
级运行这个项目时,它运行得很好。此外,从这个项目创建的.war文件运行良好。我不确定测试时出现了什么问题。
我检查了一下,IDE中出现了问题。现在一切正常。起初我很困惑,因为gradle:bootRun
运行良好,并且我能够访问这些视图HTML文件。