Spring MVC和freemarker java注解配置

时间:2016-06-13 00:38:41

标签: java spring spring-mvc freemarker

我尝试在我的项目中使用myApp.controller("myController",['$scope',function(s){ this.name="val1"; console.log("1: "+this.name); setTimeout(function(){ console.log("2: "+this.name); s.$apply(function(){ this.name="val2"; }.bind(this)); console.log("3: "+this.name); }.bind(this)); }]);作为我的模板引擎,我的观点是.JSP文件但是里面没有jsp代码,我可以将它们更改为.html但我也尝试过那我和我得到了同样的错误

这是我的JavaConfig类

user@host:~$ read < <( echo "Hello I'm a background task" & echo $! )
user@host:~$ echo $REPLY
28677

这是我的初始化程序类

freemarker

我的根配置

@Configuration
@EnableWebMvc
@ComponentScan({"configuracion", "controladores", "seguridad"})
public class ConfigMVC extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/resources/**").addResourceLocations("/WEB-INF/resources/");

    }

 @Bean
    public FreeMarkerConfigurer freemarkerConfig() {

        FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();

        freeMarkerConfigurer.setTemplateLoaderPath("/WEB-INF/views/");
        freeMarkerConfigurer.setDefaultEncoding("UTF-8");

        return freeMarkerConfigurer;
    }

@Bean
    public FreeMarkerViewResolver viewResolver() {

        FreeMarkerViewResolver viewResolver = new FreeMarkerViewResolver();
        viewResolver.setPrefix("/WEB-INF/views/");
        viewResolver.setSuffix(".jsp");
        viewResolver.setCache(false);   //Set to true during production
        viewResolver.setContentType("text/html;charset=UTF-8");
        viewResolver.setOrder(0);

        return viewResolver;
    }
}

我的春季版本为public class WebInicializar extends AbstractAnnotationConfigDispatcherServletInitializer { @Override protected Class<?>[] getRootConfigClasses() { return new Class[]{RootConfig.class}; } @Override protected Class<?>[] getServletConfigClasses() { return new Class[]{ConfigMVC.class}; } @Override protected String[] getServletMappings() { return new String[]{"/"}; } @Override protected Filter[] getServletFilters() { Filter[] singleton = {new CORSFilter()}; return singleton; } @Override protected DispatcherServlet createDispatcherServlet(WebApplicationContext servletAppContext) { final DispatcherServlet dispatcherServlet = (DispatcherServlet) super.createDispatcherServlet(servletAppContext); dispatcherServlet.setThrowExceptionIfNoHandlerFound(true); return dispatcherServlet; } ,我的freeMarker版本为@Configuration @ComponentScan(basePackages = {"controladores", "seguridad"}) @Import({ConfigMVC.class, SeguridadConfig.class}) public class RootConfig { }

这是我浏览网络应用时的错误

4.2.5.RELEASE

1 个答案:

答案 0 :(得分:1)

Freemarker使用FreemarkerConfigurer中设置的前缀。 您需要从FreeMarkerViewResolver中删除setPrefix