Java 类org.springframework.web.servlet.view.velocity.VelocityViewResolver 实例源码

项目:ssm-shiro    文件:MVConfig.java   
/**
 * 视图解析器
 * velocity
 * 过期是由于velocity六年没有更新过了,spring官方推荐使用FreeMarker或者Thymeleaf
 * 后期考虑spring官方的Thymeleaf
 */
@Bean
public ViewResolver viewResolver() {
/*    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
    viewResolver.setContentType("text/html;charset=utf-8");
    viewResolver.setPrefix("/static/");
    viewResolver.setSuffix(".html");
    return viewResolver;*/
    VelocityViewResolver velocityViewResolver = new VelocityViewResolver();
    velocityViewResolver.setCache(true);
    velocityViewResolver.setPrefix("");
    velocityViewResolver.setSuffix(".html");
    velocityViewResolver.setContentType("text/html;charset=utf-8");

    //关于Toolbox路径问题:如何路径开始头没有/会自动加上/,所以你如果写classpath:之类的识别不了
    velocityViewResolver.setToolboxConfigLocation("/WEB-INF/velocityToolBox.xml");
    velocityViewResolver.setViewClass(VelocityToolboxView.class);
    return velocityViewResolver;
}
项目:DCMonitor    文件:VelocityConfiguration.java   
@Bean
VelocityViewResolver velocityViewResolver() {
  VelocityViewResolver resolver = new VelocityViewResolver();
  resolver.setSuffix(this.environment.getProperty("suffix", ".vm"));
  resolver.setPrefix(this.environment.getProperty("prefix", "/public/"));
  // Needs to come before any fallback resolver (e.g. a
  // InternalResourceViewResolver)
  resolver.setOrder(Ordered.LOWEST_PRECEDENCE - 20);
  Properties p = new Properties();
  p.put(Velocity.FILE_RESOURCE_LOADER_PATH, "/public/");
  p.put("input.encoding", "utf-8");
  p.put("output.encoding", "utf-8");
  resolver.setAttributes(p);
  resolver.setContentType("text/html;charset=utf-8");
  return resolver;
}
项目:ARCLib    文件:VelocityProperties.java   
@Override
public void applyToViewResolver(Object viewResolver) {
    super.applyToViewResolver(viewResolver);
    VelocityViewResolver resolver = (VelocityViewResolver) viewResolver;
    resolver.setToolboxConfigLocation(getToolboxConfigLocation());
    resolver.setDateToolAttribute(getDateToolAttribute());
    resolver.setNumberToolAttribute(getNumberToolAttribute());
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:VelocityProperties.java   
@Override
public void applyToViewResolver(Object viewResolver) {
    super.applyToViewResolver(viewResolver);
    VelocityViewResolver resolver = (VelocityViewResolver) viewResolver;
    resolver.setToolboxConfigLocation(getToolboxConfigLocation());
    resolver.setDateToolAttribute(getDateToolAttribute());
    resolver.setNumberToolAttribute(getNumberToolAttribute());
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:VelocityAutoConfigurationTests.java   
@Test
public void allowSessionOverride() {
    registerAndRefreshContext("spring.velocity.allow-session-override:true");
    AbstractTemplateViewResolver viewResolver = this.context
            .getBean(VelocityViewResolver.class);
    assertThat(viewResolver).extracting("allowSessionOverride").containsExactly(true);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:VelocityAutoConfigurationTests.java   
private MockHttpServletResponse render(String viewName) throws Exception {
    VelocityViewResolver resolver = this.context.getBean(VelocityViewResolver.class);
    View view = resolver.resolveViewName(viewName, Locale.UK);
    assertThat(view).isNotNull();
    HttpServletRequest request = new MockHttpServletRequest();
    request.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE,
            this.context);
    MockHttpServletResponse response = new MockHttpServletResponse();
    view.render(null, request, response);
    return response;
}
项目:spring-boot-concourse    文件:VelocityProperties.java   
@Override
public void applyToViewResolver(Object viewResolver) {
    super.applyToViewResolver(viewResolver);
    VelocityViewResolver resolver = (VelocityViewResolver) viewResolver;
    resolver.setToolboxConfigLocation(getToolboxConfigLocation());
    resolver.setDateToolAttribute(getDateToolAttribute());
    resolver.setNumberToolAttribute(getNumberToolAttribute());
}
项目:spring-boot-concourse    文件:VelocityAutoConfigurationTests.java   
@Test
public void allowSessionOverride() {
    registerAndRefreshContext("spring.velocity.allow-session-override:true");
    AbstractTemplateViewResolver viewResolver = this.context
            .getBean(VelocityViewResolver.class);
    assertThat(viewResolver).extracting("allowSessionOverride").containsExactly(true);
}
项目:spring-boot-concourse    文件:VelocityAutoConfigurationTests.java   
private MockHttpServletResponse render(String viewName) throws Exception {
    VelocityViewResolver resolver = this.context.getBean(VelocityViewResolver.class);
    View view = resolver.resolveViewName(viewName, Locale.UK);
    assertThat(view).isNotNull();
    HttpServletRequest request = new MockHttpServletRequest();
    request.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE,
            this.context);
    MockHttpServletResponse response = new MockHttpServletResponse();
    view.render(null, request, response);
    return response;
}
项目:contestparser    文件:VelocityProperties.java   
@Override
public void applyToViewResolver(Object viewResolver) {
    super.applyToViewResolver(viewResolver);
    VelocityViewResolver resolver = (VelocityViewResolver) viewResolver;
    resolver.setToolboxConfigLocation(getToolboxConfigLocation());
    resolver.setDateToolAttribute(getDateToolAttribute());
    resolver.setNumberToolAttribute(getNumberToolAttribute());
}
项目:contestparser    文件:VelocityAutoConfigurationTests.java   
@Test
public void allowSessionOverride() {
    registerAndRefreshContext("spring.velocity.allow-session-override:true");
    AbstractTemplateViewResolver viewResolver = this.context
            .getBean(VelocityViewResolver.class);
    assertThat((Boolean) ReflectionTestUtils.getField(viewResolver,
            "allowSessionOverride"), is(true));
}
项目:contestparser    文件:VelocityAutoConfigurationTests.java   
private MockHttpServletResponse render(String viewName) throws Exception {
    VelocityViewResolver resolver = this.context.getBean(VelocityViewResolver.class);
    View view = resolver.resolveViewName(viewName, Locale.UK);
    assertThat(view, notNullValue());
    HttpServletRequest request = new MockHttpServletRequest();
    request.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE,
            this.context);
    MockHttpServletResponse response = new MockHttpServletResponse();
    view.render(null, request, response);
    return response;
}
项目:orchidae    文件:WebMvcConfig.java   
/**
 * actual resolver for the html files
 * 
 * @return
 */
@Bean
public VelocityViewResolver velocityViewResolver()
{
    VelocityViewResolver vvw = new VelocityViewResolver();
    vvw.setPrefix( "" );
    vvw.setSuffix( ".html" );
    // TODO in production we might actuall enable caching
    vvw.setCache( false );
    vvw.setExposeSpringMacroHelpers( true );
    return vvw;
}
项目:boot-examples    文件:Application.java   
@Bean
VelocityViewResolver velocityViewResolver() {
    VelocityViewResolver resolver = new VelocityViewResolver();
    resolver.setSuffix(this.environment.getProperty("suffix", ".vm"));
    resolver.setPrefix(this.environment.getProperty("prefix", "/templates/"));
    // Needs to come before any fallback resolver (e.g. a
    // InternalResourceViewResolver)
    resolver.setOrder(Ordered.LOWEST_PRECEDENCE - 20);
    return resolver;
}
项目:Daily-Email-WebApp    文件:ViewConfiguration.java   
@Bean
public ViewResolver velocityViewResolver() {
    VelocityViewResolver viewResolver = new VelocityViewResolver();
    viewResolver.setSuffix(".vm");
    viewResolver.setExposeSpringMacroHelpers(true);
    viewResolver.setOrder(1);
    viewResolver.setContentType("text/html; charset=UTF-8");
    return viewResolver;
}
项目:spring4-understanding    文件:ViewResolverRegistry.java   
private VelocityRegistration() {
    super(new VelocityViewResolver());
    getViewResolver().setSuffix(".vm");
}
项目:spring4-understanding    文件:ViewResolverRegistryTests.java   
@Test
public void velocity() {
    this.registry.velocity().prefix("/").suffix(".vm").cache(true);
    VelocityViewResolver resolver = checkAndGetResolver(VelocityViewResolver.class);
    checkPropertyValues(resolver, "prefix", "/", "suffix", ".vm", "cacheLimit", 1024);
}
项目:spring4-understanding    文件:ViewResolverRegistryTests.java   
@Test
public void velocityDefaultValues() {
    this.registry.velocity();
    VelocityViewResolver resolver = checkAndGetResolver(VelocityViewResolver.class);
    checkPropertyValues(resolver, "prefix", "", "suffix", ".vm");
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:VelocityAutoConfigurationTests.java   
@Test
public void defaultConfiguration() {
    registerAndRefreshContext();
    assertThat(this.context.getBean(VelocityViewResolver.class)).isNotNull();
    assertThat(this.context.getBean(VelocityConfigurer.class)).isNotNull();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:VelocityAutoConfigurationTests.java   
@Test
public void disableCache() {
    registerAndRefreshContext("spring.velocity.cache:false");
    assertThat(this.context.getBean(VelocityViewResolver.class).getCacheLimit())
            .isEqualTo(0);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:VelocityAutoConfigurationTests.java   
@Test
public void usesEmbeddedVelocityViewResolver() {
    registerAndRefreshContext("spring.velocity.toolbox:/toolbox.xml");
    VelocityViewResolver resolver = this.context.getBean(VelocityViewResolver.class);
    assertThat(resolver).isInstanceOf(EmbeddedVelocityViewResolver.class);
}
项目:spring-boot-concourse    文件:VelocityAutoConfigurationTests.java   
@Test
public void defaultConfiguration() {
    registerAndRefreshContext();
    assertThat(this.context.getBean(VelocityViewResolver.class)).isNotNull();
    assertThat(this.context.getBean(VelocityConfigurer.class)).isNotNull();
}
项目:spring-boot-concourse    文件:VelocityAutoConfigurationTests.java   
@Test
public void disableCache() {
    registerAndRefreshContext("spring.velocity.cache:false");
    assertThat(this.context.getBean(VelocityViewResolver.class).getCacheLimit())
            .isEqualTo(0);
}
项目:spring-boot-concourse    文件:VelocityAutoConfigurationTests.java   
@Test
public void usesEmbeddedVelocityViewResolver() {
    registerAndRefreshContext("spring.velocity.toolbox:/toolbox.xml");
    VelocityViewResolver resolver = this.context.getBean(VelocityViewResolver.class);
    assertThat(resolver).isInstanceOf(EmbeddedVelocityViewResolver.class);
}
项目:contestparser    文件:VelocityAutoConfigurationTests.java   
@Test
public void defaultConfiguration() {
    registerAndRefreshContext();
    assertThat(this.context.getBean(VelocityViewResolver.class), notNullValue());
    assertThat(this.context.getBean(VelocityConfigurer.class), notNullValue());
}
项目:contestparser    文件:VelocityAutoConfigurationTests.java   
@Test
public void disableCache() {
    registerAndRefreshContext("spring.velocity.cache:false");
    assertThat(this.context.getBean(VelocityViewResolver.class).getCacheLimit(),
            equalTo(0));
}
项目:contestparser    文件:VelocityAutoConfigurationTests.java   
@Test
public void usesEmbeddedVelocityViewResolver() {
    registerAndRefreshContext("spring.velocity.toolbox:/toolbox.xml");
    VelocityViewResolver resolver = this.context.getBean(VelocityViewResolver.class);
    assertThat(resolver, instanceOf(EmbeddedVelocityViewResolver.class));
}
项目:mongodb-aggregation    文件:Config.java   
@Bean
public VelocityViewResolver viewResolver() {
    VelocityViewResolver resolver = new VelocityViewResolver();
    resolver.setSuffix(".html");
    return resolver;
}