@Test @DisplayName("viewResolverのBeanが定義されている") public void viewResolverTest() { Method viewResolverMethod = assertDoesNotThrow(() -> MvcConfig.class.getMethod("viewResolver", SpringTemplateEngine.class)); Bean bean = viewResolverMethod.getAnnotation(Bean.class); assertNotNull(bean); ThymeleafViewResolver viewResolver = mvcConfig.viewResolver(mvcConfig.templateEngine(mvcConfig.templateResolver())); ISpringTemplateEngine templateEngine = viewResolver.getTemplateEngine(); assertAll("viewResolver not configured correctly", () -> assertTrue(templateEngine instanceof SpringTemplateEngine), () -> assertEquals(StandardCharsets.UTF_8.name(), viewResolver.getCharacterEncoding()) ); }
@Bean public ThymeleafViewResolver viewResolver(SpringTemplateEngine templateEngine) { ThymeleafViewResolver viewResolver = new ThymeleafViewResolver(); viewResolver.setTemplateEngine(templateEngine); viewResolver.setCharacterEncoding(StandardCharsets.UTF_8.name()); return viewResolver; }
MvcConfig implements WebMvcConfigurer { @Bean public ThymeleafViewResolver viewResolver(SpringTemplateEngine templateEngine) { ThymeleafViewResolver viewResolver = new ThymeleafViewResolver(); viewResolver.setTemplateEngine(templateEngine); viewResolver.setCharacterEncoding(StandardCharsets.UTF_8.name()); return viewResolver; } }
MvcConfig implements WebMvcConfigurer { @Bean public ThymeleafViewResolver viewResolver(SpringTemplateEngine templateEngine) { ThymeleafViewResolver viewResolver = new ThymeleafViewResolver(); viewResolver.setTemplateEngine(templateEngine); viewResolver.setCharacterEncoding(StandardCharsets.UTF_8.name()); return viewResolver; }  }
MvcConfig implements WebMvcConfigurer { @Bean public ThymeleafViewResolver viewResolver(SpringTemplateEngine templateEngine) { ThymeleafViewResolver viewResolver = new ThymeleafViewResolver(); viewResolver.setTemplateEngine(templateEngine); viewResolver.setCharacterEncoding(StandardCharsets.UTF_8.name()); return viewResolver; }  @Bean SpringResourceTemplateResolver templateResolver(); @Bean SpringTemplateEngine templateEngine(SpringResourceTemplateResolver templateResolver); @Bean ThymeleafViewResolver viewResolver(SpringTemplateEngine templateEngine); @Override void addResourceHandlers(ResourceHandlerRegistry registry); @Bean MessageSource messageSource(); }
MvcConfig implements WebMvcConfigurer { @Bean public ThymeleafViewResolver viewResolver(SpringTemplateEngine templateEngine) { ThymeleafViewResolver viewResolver = new ThymeleafViewResolver(); viewResolver.setTemplateEngine(templateEngine); viewResolver.setCharacterEncoding(StandardCharsets.UTF_8.name()); return viewResolver; }  @Bean SpringResourceTemplateResolver templateResolver(); @Bean SpringTemplateEngine templateEngine(SpringResourceTemplateResolver templateResolver); @Bean ThymeleafViewResolver viewResolver(SpringTemplateEngine templateEngine); @Override void addResourceHandlers(ResourceHandlerRegistry registry); @Bean MessageSource messageSource();  }