我創建了一個注釋為@Component的類InsertInitialData類,并將WebApplicationContext與autowired注釋一起使用。Thymeleaf使用上下文進行初始化,請在下面的代碼中找到。 @Componentpublic class InsertInitialData{WebApplicationContext context;@Autowiredpublic void setContext(WebApplicationContext context) { this.context = context;}@Bean //as it is from thymeleaf documentation, just passed the context! else is same!public SpringResourceTemplateResolver templateResolver(){ // SpringResourceTemplateResolver automatically integrates with Spring's own // resource resolution infrastructure, which is highly recommended. SpringResourceTemplateResolver template