【问题标题】:Getting version from pom in JSP for Spring Boot Web从 JSP 中的 pom 获取 Spring Boot Web 的版本
【发布时间】:2015-09-10 11:19:33
【问题描述】:

我试图从我的 JSP 页面中的 pom.xml 打印应用程序版本。我尝试将过滤与 Spring Boot 结合起来。 但是这些值不会在 jsp 页面中呈现。

我在 pom.xml 中添加了以下部分。

<plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <webResources>
                    <resource>
                        <directory>src/main/resources/templates</directory>
                        <filtering>true</filtering>
                    </resource>
                </webResources>
            </configuration>
        </plugin>

并在jsp页面中添加了以下内容:-

<h4>${project.description}</h4>
<h4>${project.name}</h4>
<h4>${project.version}</h4>

但是当 JSP 页面呈现时,标签是空的,里面没有值。

【问题讨论】:

    标签: java spring maven spring-boot


    【解决方案1】:

    作为described in the documentation,Spring Boot 使用@…@ 作为分隔符而不是${…}

    由于默认配置文件接受 Spring 样式占位符 (${...​}),因此 Maven 过滤更改为使用 @..@ 占位符(您可以使用 Maven 属性 resource.delimiter 覆盖它)

    这意味着您的 JSP 需要包含以下内容:

    <h4>@project.description@</h4>
    <h4>@project.name@</h4>
    <h4>@project.version@</h4>
    

    另外,AFAIK,src/main/resources/templates 的过滤应该像这样启用:

    <resources>
         <resource>
            <directory>src/main/resources/templates</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
    

    【讨论】:

      【解决方案2】:

      我试图解决同样的问题:基本上是将项目变量的值静态插入到构建时生成的 JSP 中。在运行时无需额外调用来获取属性等。这是一个为我解决它的sn-p。 我正在使用 spring,它在下面使用 maven-war-plugin。

      我将所有需要静态值的文件放入子文件夹中,因此并非所有 jsps 都被过滤。后来我静态包含这些文件。

      <plugin>
                  <artifactId>maven-war-plugin</artifactId>
                  <configuration>
                      <webResources>
                          <resource>
                              <directory>src/main/webapp/WEB-INF/jsp/version/</directory>
                              <filtering>true</filtering>
                              <targetPath>WEB-INF/jsp/version/</targetPath>
                          </resource>
                      </webResources>
                  </configuration>
              </plugin>
      

      【讨论】:

        猜你喜欢
        • 2020-07-12
        • 2021-08-31
        • 2019-06-04
        • 2021-12-13
        • 2014-01-29
        • 2016-02-01
        • 2018-03-10
        • 1970-01-01
        • 2012-04-11
        相关资源
        最近更新 更多