下面列出了怎么用org.springframework.web.servlet.view.velocity.VelocityConfigurer的API类实例代码及写法,或者点击链接到github查看源代码。
@Bean
public VelocityConfig velocityConfig() throws IOException, VelocityException {
Properties config = new Properties();
config.setProperty("input.encoding", "UTF-8");
config.setProperty("output.encoding", "UTF-8");
config.setProperty("default.contentType", "text/html;charset=UTF-8");
config.setProperty("resource.loader", "class");
config.setProperty("class.resource.loader.class",
"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
VelocityConfigurer velocityConfigurer = new VelocityConfigurer();
velocityConfigurer.setVelocityProperties(config);
velocityConfigurer.afterPropertiesSet();
return velocityConfigurer;
}
@Bean
@ConditionalOnMissingBean(VelocityConfig.class)
public VelocityConfigurer velocityConfigurer() {
VelocityConfigurer configurer = new VelocityConfigurer();
applyProperties(configurer);
return configurer;
}
/**
* Register Velocity view resolver with an empty default view name
* prefix and a default suffix of ".vm".
*
* <p><strong>Note</strong> that you must also configure Velocity by adding a
* {@link org.springframework.web.servlet.view.velocity.VelocityConfigurer} bean.
*/
public UrlBasedViewResolverRegistration velocity() {
if (this.applicationContext != null && !hasBeanOfType(VelocityConfigurer.class)) {
throw new BeanInitializationException("In addition to a Velocity view resolver " +
"there must also be a single VelocityConfig bean in this web application context " +
"(or its parent): VelocityConfigurer is the usual implementation. " +
"This bean may be given any name.");
}
VelocityRegistration registration = new VelocityRegistration();
this.viewResolvers.add(registration.getViewResolver());
return registration;
}
@Before
public void setUp() {
StaticWebApplicationContext context = new StaticWebApplicationContext();
context.registerSingleton("freeMarkerConfigurer", FreeMarkerConfigurer.class);
context.registerSingleton("velocityConfigurer", VelocityConfigurer.class);
context.registerSingleton("tilesConfigurer", TilesConfigurer.class);
context.registerSingleton("groovyMarkupConfigurer", GroovyMarkupConfigurer.class);
context.registerSingleton("scriptTemplateConfigurer", ScriptTemplateConfigurer.class);
this.registry = new ViewResolverRegistry();
this.registry.setApplicationContext(context);
this.registry.setContentNegotiationManager(new ContentNegotiationManager());
}
@Bean
public VelocityEngine velocityEngine(VelocityConfigurer configurer)
throws VelocityException, IOException {
return configurer.getVelocityEngine();
}
@Bean
public VelocityConfigurer velocityConfigurer() {
VelocityConfigurer configurer = new VelocityConfigurer();
configurer.setResourceLoaderPath("/WEB-INF/");
return configurer;
}
@Bean
VelocityConfigurer velocityConfig() {
return new VelocityConfigurer();
}
@Bean
VelocityConfigurer velocityConfig() {
return new VelocityConfigurer();
}
@Bean
public VelocityConfigurer velocityConfig() {
VelocityConfigurer velocityConfigurer = new VelocityConfigurer();
velocityConfigurer.setResourceLoaderPath("/");
return velocityConfigurer;
}
@Bean
public VelocityConfigurer velocityConfig() {
VelocityConfigurer velocityConfigurer = new VelocityConfigurer();
velocityConfigurer.setResourceLoaderPath("/");
return velocityConfigurer;
}