Tag: velocity

由于路径差异java,spring mvc,velocity找不到JS / CSS文件

我有这个目录结构: webapp – resources – custom.js – base.css – WEB-INF – views – layout.vm – top.vm – footer.vm – index.vm – FolderA – restricted.vm 我的layout.vm是: #parse(‘top.vm’) $screen_content #parse(‘footer.vm’) 我的top.vm包括这些JS和CSS文件: 现在当我访问http://www.example.com:8080/index页面时,我看到JS和CSS文件被找到了。 但是当我访问http://www.example.com:8080/FolderA/restricted时 ,找不到JS和CSS文件。 当它在顶部我改变它时它起作用 但随后索引页面被破坏了。 我使用spring控制器返回适当的视图。 例如,以下内容返回索引页面: @RequestMapping(value = “/”, method = RequestMethod.GET) public String home(Model model) { return “index”; } 这会返回受限制的视图: @Controller @RequestMapping(value = “/FolderA”) […]

Eclipse AutoValue类无法构建

我正在运行Eclipse Kepler SR2,Maven 3.1.1附带了m2e和m2e-apt插件,我收到一个错误,我不知道如何解决。 我设法找到使@AutoValue工作到我的pom.xml所需的所有依赖项,但现在我处于一种状态,只有当需要定义的方法都具有原始返回类型时它才有效。 如果我提供一个返回Object或更具体的抽象getter,我会收到此错误: @AutoValue processor threw an exception: java.lang.IllegalArgumentException: Failed to invoke com.google.auto.value.processor.AutoValueProcessor$Property.nullable() on getObject… 我已经尝试了基础知识 – 清除了maven缓存,重新启动了Eclipse,重建了项目……没有骰子。 所以我深入研究了源代码,发现了一个差异,我不确定它是如何解决的。 在生成的AutoValue类的Velocity模板中,有一些基本逻辑用于渲染基元,而不是对象,例如在第37行,检查p.nullable 。 p变量是AutoValueProcessor$Property类的一个实例,可以isNullable()一个链接的第205行看到,它有一个isNullable()方法,但是没有nullable方法或属性。 那么Velocity呈现阶段是如何工作的呢? Velocity是否自动将p.nullable扩展为p.isNullable一些如何,但不是因为我的原因? 这是一个错误吗? 我不知道该怎么做。 不编译的示例类: @AutoValue public abstract class Point { public static Point of(double x, double y) { return new AutoValue_Point(x, y); } public abstract Double x(); public abstract […]

使用ExecutorService执行异步任务时出现问题

我之前曾问过一个关于ExecutorService和Apache Velocity初始化的问题。 为了快速回顾一下 – 我有一个接受用户请求的Java EE前端,然后对于每个请求,使用ExecutorService(设置为守护进程的SingleThreadedExecutor)启动冗长的工作流。此工作流包含在库中并且可以工作当通过eclipse在独立模式下运行时,正如预期的那样。 当从网站(servlet)调用时,我观察到工作流一直在Velocity Engine初始化的位置(Velocity.init()或ve.init())。 因此我的上述问题。 当没有任何答案/建议有效时,我推断这与Velocity启动并决定转向FreeMarker的方式有关。 现在我看到工作流程也悬挂在FreeMarker实现的完全相同的位置。 这个’place’是邮件构建部分,它根据传递的数据对象的coupel评估模板并返回邮件字符串。调用Freemark’ing类和FreeMark类的类如下 – public class mailBuilder { private static final Logger log = Logger.getLogger( mailBuilder.class ); static String a; static String b; public mailBuilder(CustomDataStructure input) { a = input.getA(); b = input.getB(); } public static String returnMailstring() throws Exception { log.info(“Gathering elements to construct email.”); […]

速度和log4J错误

我构建了一个在我的localhost(tomcat)中完美运行的webapp。 但是当我尝试部署时,在init()中速度崩溃,让我在这里留下这个奇怪的堆栈跟踪(抱歉大小): ERROR [main] (VelocityConfigurator.java:62) – Error initializing Velocity! org.apache.velocity.exception.VelocityException: Failed to initialize an instance of org.apache.velocity.runtime.log.Log4JLogChute with the current runtime configuration. at org.apache.velocity.runtime.log.LogManager.createLogChute(LogManager.java:206) at org.apache.velocity.runtime.log.LogManager.updateLog(LogManager.java:255) at org.apache.velocity.runtime.RuntimeInstance.initializeLog(RuntimeInstance.java:795) at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:250) at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:589) at org.apache.velocity.runtime.RuntimeSingleton.init(RuntimeSingleton.java:229) at org.apache.velocity.app.Velocity.init(Velocity.java:107) at com.webcodei.velociraptor.velocity.VelocityConfigurator.initVelocity(VelocityConfigurator.java:57) at com.webcodei.velociraptor.velocity.VelocityConfigurator.configure(VelocityConfigurator.java:42) at com.webcodei.velociraptor.VelociListener.contextInitialized(VelociListener.java:26) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4336) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:761) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:741) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525) at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626) at […]

Springboot 1.5.x的速度

使用Springboot 1.4.4,我可以直接使用VelocityEngine作为bean。 我使用application.properties进行的配置: spring.velocity.properties.resource.loader=jar spring.velocity.properties.jar.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader spring.velocity.properties.jar.runtime.log.logsystem.class=org.apache.velocity.runtime.log.SimpleLog4JLogSystem spring.velocity.properties.jar.runtime.log.logsystem.log4j.category=velocity spring.velocity.cache=true spring.velocity.charset=UTF-8 在Springboot 1.5.x中,不再有Velocity支持。 在Springboot 1.5.x中集成此配置的最佳方法是什么? 我已经添加了依赖项: org.apache.velocity velocity 1.7 并创建了Bean: @Bean VelocityEngine velocityEngine(){ return new VelocityEngine(); } 但是属性遗失了。 同 @Autowired ConfigurableEnvironment configurableEnvironment; 我可以解析属性,但感觉不对。

如何从Velocity模板访问对象的公共字段

这是我的对象类: public class Address { public final String line1; public final String town; public final String postcode; public Address(final String line1, final String town, final String postcode) { this.line1 = line1; this.town = town; this.postcode = postcode; } } 我将它添加到速度上下文中,如下所示: Address theAddress = new Address(“123 Fake St”, “Springfield”, “SP123”); context.put(“TheAddress”, theAddress); 但是,在编写模板时,以下内容不会呈现地址字段(但是,当我将getter添加到Address类时它可以正常工作) ${TheAddress.line1} ${TheAddress.town} ${TheAddress.postcode} […]

用java替换word文档模板中的变量

我想加载一个模板word文档来添加内容并保存为新文档。 我正在研究.doc文件。 经过长时间的研究,我只找到了docx的解决方案: http://www.smartjava.org/content/create-complex-word-docx-documents-programatically-docx4j Mail merge in java for Microsoft Word document – Part I 所以我想替换以这种格式编写的任何变量: $VAR由其值。 我可以用velocity或Apache-poi来做,它的最佳解决方案是什么。 任何帮助将不胜感激。