使用ClasspathLoader
ClasPathLoaderclassPathLoader=newClasPathLoader("templates/")beetlGroupUtilConfiguration.setResourceLoader(classPathLoader);
假设你的模板在templates目录下
太棒了。。解决了。。我以前都是这么写的ClasspathResourceLoader("/templates")为什么斜杠放后面就解决了呢?
你的模板在jar中,所以不能用WebResourceLoader(它是按照文件路径加载的),你可以用ClasspathLoader试试http://git.oschina.net/xiandafu/springboot_beetl_beetlsql参考这个工程
@闲大赋
这个问题在切换成springboot1.4版本后依然存在。
引用来自“闲大赋”的评论
使用ClasspathLoader
ClasPathLoaderclassPathLoader=newClasPathLoader("templates/")beetlGroupUtilConfiguration.setResourceLoader(classPathLoader);
假设你的模板在templates目录下
没有ClassPathLoader这个类,这个类是sun.rmi.rmic.iiop的?我现在能正常运行,但是执行不了单元测试,Maven的打包的时候执行测试都可以通过,手动执行测试就不行,报如下错误:
java.io.FileNotFoundException:classpathresource[resources/]cannotberesolvedtoabsolutefilepathbecauseitdoesnotresideinthefilesystem:jar:file:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/lib/ant-javafx.jar!/resources/
请问能不能把你的配置给我看看,我也出现你那个问题了。
写得不错,鼓励一下,再分享一份资料。
http://www.marsitman.com/springboot/springboot_helloworld.html
我是这样配置的,可以启动
@Value("${RESOURCE.root:/templates}") StringresourceRoot;//模板跟目录
@Bean(initMethod="init",name="beetlConfig") publicBeetlGroupUtilConfigurationgetBeetlGroupUtilConfiguration(){ BeetlGroupUtilConfigurationbeetlGroupUtilConfiguration=newBeetlGroupUtilConfiguration(); ClasspathResourceLoaderclassPathLoader=newClasspathResourceLoader(this.getClass().getClassLoader(), resourceRoot); beetlGroupUtilConfiguration.setResourceLoader(classPathLoader); //读取配置文件信息 ResourcePatternResolverpatternResolver=ResourcePatternUtils .getResourcePatternResolver(newDefaultResourceLoader()); beetlGroupUtilConfiguration.setConfigFileResource(patternResolver.getResource("classpath:beetl.properties")); returnbeetlGroupUtilConfiguration; }
@Bean(name="beetlViewResolver") publicBeetlSpringViewResolvergetBeetlSpringViewResolver( @Qualifier("beetlConfig")BeetlGroupUtilConfigurationbeetlGroupUtilConfiguration){ BeetlSpringViewResolverbeetlSpringViewResolver=newBeetlSpringViewResolver(); beetlSpringViewResolver.setContentType("text/html;charset=UTF-8"); //beetlSpringViewResolver.setPrefix("/"); beetlSpringViewResolver.setSuffix(".html"); beetlSpringViewResolver.setOrder(0); beetlSpringViewResolver.setConfig(beetlGroupUtilConfiguration); returnbeetlSpringViewResolver; }
你好,请问怎么配置beet模板在webapp路径下?