简体   繁体   English

Intellij Idea Spring Boot Launcher:Taglibs不在Freemarker中加载

[英]Intellij idea spring boot launcher: taglibs doesn't load in freemarker

I have web app which is launched on the spring boot 2.0.4. 我有一个在春季启动2.0.4上启动的Web应用程序。 Dependencies also exists taglibs-standard-impl 1.2.5. 依赖关系还存在taglibs-standard-impl 1.2.5。
My project structure is as follows. 我的项目结构如下。

web/
├── src
   ├── main
   │   ├── java
   │   │   
   │   ├── resources
   │   │   ├── i18n
   │   │   ├── static
   │   │   └── templates
   │   └── webapp
   │       ├── META-INF
   │       └── WEB-INF
   └── test
       └── java

In WEB-INF i have folder tld with one custom tld. 在WEB-INF中,我有一个自定义tld文件夹tld。 My main class: 我的主班:

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
public class WebMain extends SpringBootServletInitializer implements WebApplicationInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(WebMain.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(WebMain.class, args);
    }
}

The problem is the following and basically it affects the development time. 问题如下,并且基本上会影响开发时间。 In my main freemarker template i include taglibs, for example: 在我的主要freemarker模板中,我包括taglib,例如:

<#assign form=JspTaglibs["http://www.springframework.org/tags/form"]/>
<#assign spring=JspTaglibs["http://www.springframework.org/tags"]/>
<#assign common = JspTaglibs["/WEB-INF/tld/common.tld"]>

And the problem is that when running in the intellij IDEA via the spring boot launcher, these taglibs can not boot correctly. 问题是,当通过spring boot启动器在intellij IDEA中运行时,这些标记库无法正确启动。 If I deploy war in Tomcat or run directly without intellij like java -jar web.war, all is well, taglibs is loaded. 如果我在Tomcat中部署war或在没有intellij的情况下直接运行(如java -jar web.war),一切都很好,将加载taglibs。

As I understood when debugging, the problem is that it can not find the WEB-INF folder in TaglibFactory class if it uses the spring boot launcher of IntellijIdea. 据我了解,调试时,问题在于,如果它使用IntellijIdea的spring boot启动器,则无法在TaglibFactory类中找到WEB-INF文件夹。 In it, any calls caused through 在其中,任何通过

servletContext.getResourcePaths (path);

where path starts with "/WEB-INF", always return null and accordingly nothing can not be loaded to tldLocations. 其中路径以“ / WEB-INF”开头,始终返回null,因此无法将任何内容加载到tldLocations。 Intellij have 4 types shorten command lines: none, JAR manifest, classpath file and user-local-default: none. Intellij有4种缩短命令行的类型:无,JAR清单,类路径文件和用户本地默认值:无。 I tried to use them all, but everything also remained. 我试图全部使用它们,但所有内容仍然保留。 For example, JAR manifest generate command like like this: 例如,JAR清单生成命令如下所示:

/usr/lib/jvm/java-8-oracle/bin/java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:40359,suspend=y,server=n -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -javaagent:/home/birthright/IDEA/lib/rt/debugger-agent.jar=file:/tmp/capture128.props -Dfile.encoding=UTF-8 -classpath /tmp/classpath1030746450.jar com.birthright.WebMain

Is it possible to solve this problem? 有可能解决这个问题吗?

WAR deployment differs in many aspects from running the application via the Spring Boot run configuration inside the IDE. WAR部署在许多方面与通过IDE中的Spring Boot运行配置运行应用程序不同。 You can try to replicate all the packaging Gradle/Maven does in your run configuration eg via IntelliJ's artifacts. 您可以尝试通过运行IntelliJ的工件来复制Gradle / Maven在运行配置中所做的所有包装。

Not sure where exactly your TLD files are when you launch the application directly from the IDE, but certainly they aren't on one of the places that the JSP specification specifies, and by default TaglibFactory follows the specs. 不知道直接从IDE启动应用程序时TLD文件的确切位置,但是可以肯定它们不在JSP规范指定的位置之一,并且默认情况下TaglibFactory遵循规范。 But you could configure it otherwise by calling setMetaInfTldSources or setClasspathTlds . 但是您可以通过调用setMetaInfTldSourcessetClasspathTlds来进行其他配置。 So you have to tweak the TaglibFactory that Spring uses; 因此,您必须调整Spring使用的TaglibFactory see examples of that in Custom EL functions won't be loaded because no ObjectWarpper was specified . 请参见Custom EL函数中的示例, 因为未指定ObjectWarpper,因此不会加载

BTW, what FreemarkerServlet does (which is not used by Spring AFAIR) is that you can set the org.freemarker.jsp.classpathTlds and org.freemarker.jsp.metaInfTldSources Java system properties to do this, so that you can do these tweaks purely in the IDE launch configuration (eg you add -Dorg.freemarker.jsp.metaInfTldSources=classpath to the Java options). 顺便说一句, FreemarkerServlet所做的事情(Spring AFAIR不使用)是您可以设置org.freemarker.jsp.classpathTldsorg.freemarker.jsp.metaInfTldSources Java系统属性来执行此操作,以便您可以完全进行这些调整在IDE启动配置中(例如,将-Dorg.freemarker.jsp.metaInfTldSources=classpath添加到Java选项)。 That's an idea you could easily re-implement. 这是一个您可以轻松地重新实现的想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM