Spring boot ThymeleafView:java.lang.IllegalArgumentException:Property';地点';是必需的

Spring boot ThymeleafView:java.lang.IllegalArgumentException:Property';地点';是必需的,spring-boot,spring-mvc,thymeleaf,Spring Boot,Spring Mvc,Thymeleaf,我按照下面的教程一步一步地完成第10个渲染模板片段 我得到一个异常:嵌套异常是java.lang.IllegalArgumentException:属性'locale'是必需的 我的代码在下面,有人能告诉我如何修复它吗?多谢各位 WebConfig.java public class WebConfig implements WebMvcConfigurer { @Autowired private WebApplicationContext context; @Bean public S

我按照下面的教程一步一步地完成第10个渲染模板片段

我得到一个异常:嵌套异常是java.lang.IllegalArgumentException:属性'locale'是必需的

我的代码在下面,有人能告诉我如何修复它吗?多谢各位

WebConfig.java

public class WebConfig implements WebMvcConfigurer {

@Autowired
private WebApplicationContext context;

@Bean
public ServletContextTemplateResolver templateResolver() {
    final ServletContextTemplateResolver resolver = new ServletContextTemplateResolver(context.getServletContext());
    resolver.setPrefix("/WEB-INF/views/");
    resolver.setSuffix(".html");
    resolver.setTemplateMode(TemplateMode.HTML);
    return resolver;
}

@Bean
public SpringTemplateEngine templateEngine() {
    SpringTemplateEngine templateEngine = new SpringTemplateEngine();
    templateEngine.setTemplateResolver(templateResolver());
    return templateEngine;
}

@Bean
public ThymeleafViewResolver viewResolver() {
    ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
    viewResolver.setTemplateEngine(templateEngine());
    return viewResolver;
}

@Bean("messageSource")
public MessageSource messageSource() {
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasenames("lang/messages");
    messageSource.setDefaultEncoding("UTF-8");
    return messageSource;
}

@Bean
public LocaleResolver localeResolver() {
    return new CookieLocaleResolver();
}

@Override
public void addInterceptors(InterceptorRegistry registry) {
    LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
    localeChangeInterceptor.setParamName("lang");
    registry.addInterceptor(localeChangeInterceptor);
}

@Bean(name = "content-part")
@Scope("prototype")
public ThymeleafView someViewBean() {
    ThymeleafView view = new ThymeleafView("index"); // templateName = 'index'
    view.setMarkupSelector("content");
    return view;
}
}

HomeController.java

public class HomeController {
@RequestMapping("/showContentPart")
public String showContentPart(final Locale locale, HttpServletRequest request, HttpServletResponse response) {
    return "content-part";
}
}

index.html 试试这个:

@请求映射(“/showContentPart”)

公共类家庭控制器 { 公共字符串showContentPart(最终区域设置、HttpServletRequest请求、HttpServletResponse响应){ 返回“内容部分”; }试试这个:

@请求映射(“/showContentPart”)

公共类家庭控制器 { 公共字符串showContentPart(最终区域设置、HttpServletRequest请求、HttpServletResponse响应){ 返回“内容部分”; }