我尝试构建我的 Spring Boot Web 应用程序并创建 jar 文件以将其部署在专用服务器上。当我使用 IDE(在我的例子中为 Intellij Idea)构建它时,一切正常。但是当我尝试执行 jar 并获取使用 thymeleaf extras 标签(如 sec:authorize)的页面时,我收到这样的异常
org.thymeleaf.exceptions.ConfigurationException: The Spring-version-specific infrastructure could not create utility for the specific version of Spring being used. Currently only Spring 6.x or newer is supported.
at org.thymeleaf.extras.springsecurity6.util.SpringVersionSpecificUtils.<clinit>(SpringVersionSpecificUtils.java:74) ~[pastebin.jar:1.0-SNAPSHOT]
at org.thymeleaf.extras.springsecurity6.util.SpringSecurityContextUtils.getAuthenticationObject(SpringSecurityContextUtils.java:127) ~[pastebin.jar:1.0-SNAPSHOT]
at org.thymeleaf.extras.springsecurity6.auth.AuthUtils.getAuthenticationObject(AuthUtils.java:102) ~[pastebin.jar:1.0-SNAPSHOT]
at org.thymeleaf.extras.springsecurity6.dialect.processor.AuthorizeAttrProcessor.isVisible(AuthorizeAttrProcessor.java:67) ~[pastebin.jar:1.0-SNAPSHOT]
at org.thymeleaf.standard.processor.AbstractStandardConditionalVisibilityTagProcessor.doProcess(AbstractStandardConditionalVisibilityTagProcessor.java:61) ~[pastebin.jar:1.0-SNAPSHOT]
at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74) ~[pastebin.jar:1.0-SNAPSHOT]
at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95) ~[pastebin.jar:1.0-SNAPSHOT]
at org.thymeleaf.util.ProcessorConfigurationUtils$ElementTagProcessorWrapper.process(ProcessorConfigurationUtils.java:633) ~[pastebin.jar:1.0-SNAPSHOT]
at org.thymeleaf.engine.ProcessorTemplateHandler.handleOpenElement(ProcessorTemplateHandler.java:1314) ~[pastebin.jar:1.0-SNAPSHOT]
at org.thymeleaf.engine.OpenElementTag.beHandled(OpenElementTag.java:205) ~[pastebin.jar:1.0-SNAPSHOT]
at org.thymeleaf.engine.TemplateModel.process(TemplateModel.java:136) ~[pastebin.jar:1.0-SNAPSHOT]
at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:661) ~[pastebin.jar:1.0-SNAPSHOT]
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1103) ~[pastebin.jar:1.0-SNAPSHOT]
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1077) ~[pastebin.jar:1.0-SNAPSHOT]
at org.thymeleaf.spring6.view.ThymeleafView.renderFragment(ThymeleafView.java:372) ~[pastebin.jar:1.0-SNAPSHOT]
at org.thymeleaf.spring6.view.ThymeleafView.render(ThymeleafView.java:192) ~[pastebin.jar:1.0-SNAPSHOT]
...
正如你所看到的,spring 认为某些依赖项的版本低于 6。但是在我的 pom.xml 中,我使用 spring-boot-starter-parent ,它应该提供正确的版本,我相信它确实如此。
pom.xml
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.3</version>
</parent>
<groupId>org.example</groupId>
<artifactId>pastebin</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>pastebin Maven Webapp</name>
<properties>
<maven.compiler.source>18</maven.compiler.source>
<maven.compiler.target>18</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-messaging</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-crypto</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity6</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring6</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId>
<version>9.37.3</version>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.16.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.0.0-jre</version>
</dependency>
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>9.2.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.12.1</version>
<configuration>
<source>18</source>
<target>18</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<addResources>true</addResources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<archive>
<manifest>
<mainClass>com.vladpochuev.config.PastebinApplication</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<finalName>pastebin</finalName>
</build>
</project>
我检查了 Maven 构建
mvn dependency:tree
我也遇到了完全相同的问题。当我运行
mvn spring-boot:run
时它会起作用,但当我将它作为 JAR 文件运行时则不起作用。然后我注意到一些奇怪的事情。在第一个实例中它会写 HHH000412: Hibernate ORM core version 6.4.2.Final
,但在另一个实例中会写 HHH000412: Hibernate ORM core version 0.0.5-SNAPSHOT
。
当我将 pom.xml 中的项目版本更改为 6.0.5-SNAPSHOT 时,它就起作用了!似乎是百里香额外的一个长期存在的错误。