mustache-spring-view icon indicating copy to clipboard operation
mustache-spring-view copied to clipboard

Java based configuration

Open samspot opened this issue 11 years ago • 3 comments

I posted a similar question to SO about java-based configuration: http://stackoverflow.com/questions/25311299/spring-java-based-config-resourceloader

Is this correct? I am getting a null pointer from a missing ResourceLoader.

@Configuration
@ComponentScan(basePackageClasses = Application.class, includeFilters = @Filter(Controller.class), useDefaultFilters = false)
class WebMvcConfig extends WebMvcConfigurationSupport {
    @Bean
    public MustacheViewResolver viewResolver() {
        MustacheViewResolver resolver = new MustacheViewResolver();
        resolver.setPrefix("/WEB-INF/views/mustache/");
        resolver.setSuffix("hbs");
        resolver.setCache(true);

        resolver.setTemplateFactory(new MustacheJTemplateFactory());
        return resolver;
    }
}

samspot avatar Aug 14 '14 17:08 samspot

In case anyone else has the same problem, I posted an answer to the StackOverflow question.

ghost avatar Sep 25 '14 05:09 ghost

I think I see the problem. JMustacheTemplateLoader and MustacheJTemplateFactory both rely on the application context injecting the ResourceLoader via implementing ResourceLoaderAware.

I think there might be a few @Autowired missing.

@bsutherland's answer on SO is a good work around for now.

I'll see about getting this fixed.

sps avatar Sep 25 '14 22:09 sps

Thanks sps!

I'm also having trouble with the i18n configuration using Java annotations. Here's what I have:

@Bean
public LocalizationMessageInterceptor getLocalizationMessageInterceptor() {
    LocalizationMessageInterceptor lmi = new LocalizationMessageInterceptor();
    lmi.setLocaleResolver(new FixedLocaleResolver(Locale.JAPAN));
    lmi.setMessageSource(messageSource);
    return lmi;
}

But my messages are not being resolved. Maybe related?

ghost avatar Sep 26 '14 07:09 ghost