Java Intellij idea spring启动程序:taglibs不';自由标记中的t负载
我有一个在spring boot 2.0.4上启动的web应用程序。 依赖项也存在于taglibs标准impl 1.2.5。Java Intellij idea spring启动程序:taglibs不';自由标记中的t负载,java,spring,spring-boot,intellij-idea,freemarker,Java,Spring,Spring Boot,Intellij Idea,Freemarker,我有一个在spring boot 2.0.4上启动的web应用程序。 依赖项也存在于taglibs标准impl 1.2.5。 我的项目结构如下 web/ ├── src ├── main │ ├── java │ │ │ ├── resources │ │ ├── i18n │ │ ├── static │ │ └── templates │ └── webapp │ ├── META
我的项目结构如下
web/
├── src
├── main
│ ├── java
│ │
│ ├── resources
│ │ ├── i18n
│ │ ├── static
│ │ └── templates
│ └── webapp
│ ├── META-INF
│ └── WEB-INF
└── test
└── java
在WEB-INF中,我有一个带有自定义tld的文件夹tld。
我的主要班级:
@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);
}
}
问题如下,基本上影响了开发时间。在我的主要freemarker模板中,我包括标记库,例如:
<#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"]>
路径以“/WEB-INF”开头时,始终返回null,因此不能将任何内容加载到tldLocations。
Intellij有4种类型:无、JAR清单、类路径文件和用户本地默认值:无。
我试图全部使用它们,但所有东西都保留了下来。
例如,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
有可能解决这个问题吗?WAR部署在许多方面与通过IDE内的Spring引导运行配置运行应用程序不同。您可以尝试复制Gradle/Maven在运行配置中的所有打包功能,例如通过IntelliJ的工件。当您直接从IDE启动应用程序时,不确定TLD文件的确切位置,但它们肯定不在JSP规范指定的位置之一,默认情况下,
TaglibFactory
遵循规范。但您可以通过调用setMetaInfTldSources
或setClasspathTlds
对其进行其他配置。因此,您必须调整Spring使用的TaglibFactory
;请参见中的示例
顺便说一句,
FreemarkerServlet
所做的(Spring AFAIR不使用)是,您可以设置org.freemarker.jsp.classpathTlds
和org.freemarker.jsp.metaInfTldSources
Java系统属性来完成此操作,这样您就可以纯粹在IDE启动配置中进行这些调整(例如,您将-Dorg.freemarker.jsp.metaInfTldSources=classpath
添加到Java选项中)。这是一个您可以轻松重新实现的想法。我不太清楚我应该在setMetaInfTldSources方法中指定什么来加载我的自定义tld和我在帖子中指定的其他Spring。我匆忙阅读了您的原始问题…查看我的注释。您可以使用IntelliJ将webapp
添加到运行时类路径吗?然后classpathTlds
可能会有所帮助。我想这与直接从jar
运行Spring Boot应用程序时是一样的src/main/webapp
不包括在其中,这与构建war
时不同。因此,从IDE启动应用程序时,肯定无法从src/main/webapp
加载任何内容,因为它不是在类路径中,其内容也不是通过ServletContext
作为资源可见的。对吗?@ddekany对。在TaglibFactory.get(String tagliburi)方法中,他尝试在TldLocation explicitlyMappedTldLocation=getExplicitlyMappedTldLocation(tagliburi)行中加载tld位置;行,但始终返回null,然后抛出TaglibGettingException。是的,如果我构建jar并通过java-jar web.jar启动,我会得到相同的错误,war都很好。Standalone(jar)Spring Boot允许您将内容放入src/main/resources/static/
(以及更多:),而不是src/main/webapp
。我假设它还将这些资源公开为ServletContext
资源。但是,当您将其部署为war时,它可能不起作用……另一个有趣的可能性是,如果应用程序检测到您已通过系统属性请求该资源(我的意思是,例如,使用该属性),然后它调整TomcatEmbeddedServletContainerFactory,将webapp
添加为servlet上下文资源根。您可以在此处找到添加资源根的示例:。作为可选操作,它不会干扰war部署。
/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