# \#spring

**URL:** https://www.isharkfly.com/tag/spring/10.md

[Latest](https://www.isharkfly.com/latest.md) · [Categories](https://www.isharkfly.com/categories.md) · [Tags](https://www.isharkfly.com/tags.md)

---

## [Webjars 导入到 SpringBoot 项目](https://www.isharkfly.com/t/webjars-springboot/18661)

<div class="topic-metadata">

**Author:** [@hex](https://www.isharkfly.com/u/hex)\
**Replies:** 0\
**Last updated:** [February 18, 2026, 9:19pm UTC](https://www.isharkfly.com/t/webjars-springboot/18661 "2026-02-18T21:19:56Z")

</div>

WebJars 是一个开源项目，旨在将客户端的 Web 库（如 JavaScript 和 CSS 库）打包成 JAR 文件，以便在 Java 项目中更方便地管理和使用。该项目的主要编程语言是 Scala，同时也使用了 HTML、Shell、Batchfile、JavaScript、SCSS 等多种语言来实现其功能。 用土话来说就是直接把前端使用的 JS 和 CSS 打包成 Jar 后直接使用。 例如，如果我们需要在项目中使用 boo…

---

## [Spring 运行的时候提示数据库方言错误](https://www.isharkfly.com/t/spring/18469)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 1\
**Last updated:** [February 2, 2026, 1:42pm UTC](https://www.isharkfly.com/t/spring/18469 "2026-02-02T13:42:18Z")

</div>

aused by: java.lang.ClassNotFoundException: org.hibernate.dialect.PostgreSQL82Dialect 问题和解决 上面的问题不是因为数据库配置的问题导致的。 而是在 pom 文件中。 \<!-- hibernate enhancement --\> \<dependency\> \<groupId\>com.…

---

## [Spring Security 介绍中的 servlet 和 reactive](https://www.isharkfly.com/t/spring-security-servlet-reactive/14116)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [September 29, 2022, 11:35am UTC](https://www.isharkfly.com/t/spring-security-servlet-reactive/14116 "2022-09-29T11:35:51Z")

</div>

最近在看看 Spring Security 中的内容。看到了下面一段话，还挺拗口的。 Spring Security 提供了一个 验证（authentication）, 授权（authorization），和保护常见攻击 的框架。 Spring security 是一个强大的，并且可以高度定制的身份验证和访问控制框架，能够同时支持 imperative 和 reactive应用， Spring security 已经成为保护 Spr…

---

## [Spring @PostMapping 能在 URL 中带有参数吗](https://www.isharkfly.com/t/spring-postmapping-url/14095)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [September 11, 2022, 1:55pm UTC](https://www.isharkfly.com/t/spring-postmapping-url/14095 "2022-09-11T13:55:47Z")

</div>

有个比较简单的问题。 Spring 的 @PostMapping 在使用 POST 提交的时候，能不能在 URL 中带参数？ 简答 短回答肯定是可以的。 在非常早期的 Web 开发的时候，我们会通过网页的 JSP 来提交表单，在这个表单提交的时候，有一个非常困惑的问题就是如果不指定 POST 的提交参数。 所有的表单数据都会拼装成 URL 中参数来进行提交。 所以 POST 是肯定可以带参数的。 Spring RestCon…

---

## [Spring Data @Repository 的分页查询](https://www.isharkfly.com/t/spring-data-repository/14097)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [September 11, 2022, 2:37pm UTC](https://www.isharkfly.com/t/spring-data-repository/14097 "2022-09-11T14:37:05Z")

</div>

分页查询在网站的设计中必不可少。 分页查询有几种方式，通常用的是：网页分页和后端分页。 不要觉得现在还有人用网页分页的方式吗？ 相信我，奇葩远比想象得多。经历过一个项目，全部都是网页分页，后端都是大量的 JOIN 和毫无人性的返回几千条记录。 为什么不返回上万条？那是因为后台数据库不大，只有 5 万多点的数据量。连个 Limit 都懒得用的项目还堂而皇之的上线运行了好几年到不重做差不多就没法用的地步。 我们来说说基于 Spri…

---

## [Spring 项目进行测试的时候提示 @SpringBootConfiguration 没有配置](https://www.isharkfly.com/t/spring-springbootconfiguration/14073)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [August 25, 2022, 8:29pm UTC](https://www.isharkfly.com/t/spring-springbootconfiguration/14073 "2022-08-25T20:29:01Z")

</div>

提示的配置信息为： java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test at org.springframework.util.Assert.state(Asser…

---

## [Spring 构建的 API 项目无法启动 Tomcat 的问题](https://www.isharkfly.com/t/spring-api-tomcat/14072)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [August 25, 2022, 7:29pm UTC](https://www.isharkfly.com/t/spring-api-tomcat/14072 "2022-08-25T19:29:28Z")

</div>

这个问题是典型的 Spring 包冲突问题。 错误日志： 5:22:24.990 \[main\] ERROR o.apache.catalina.core.ContainerBase - A child container failed during start java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed…

---

## [Spring Data 测试时的 Repository 提示为空对象](https://www.isharkfly.com/t/spring-data-repository/14071)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [August 25, 2022, 5:44pm UTC](https://www.isharkfly.com/t/spring-data-repository/14071 "2022-08-25T17:44:21Z")

</div>

错误信息如下： java.lang.NullPointerException at com.usvisatrack.common.data.tests.jpa.UserRepositoryTest.testInsert(UserRepositoryTest.java:57) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Metho…

---

## [@DataJpaTest 进行测试的坑](https://www.isharkfly.com/t/datajpatest/14070)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [August 25, 2022, 12:29pm UTC](https://www.isharkfly.com/t/datajpatest/14070 "2022-08-25T12:29:08Z")

</div>

@DataJpaTest 这个注解主要用来在 Spring 项目中测试 JPA 数据源。 默认情况下，带有 @DataJpaTest 注解的测试使用嵌入式内存数据库。 因此 @DataJpaTest 这个注解还是有点坑的。 默认数据库 默认采用的是嵌入的 H2 数据库。 就算你配置了数据库链接，如果你不使用下面的注解的话，@DataJpaTest 还是会使用配置的默认数据库。 使用注解： @AutoConfigureTest…

---

## [Spring Boot 运行的时候提示日志错误](https://www.isharkfly.com/t/spring-boot/14069)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [August 24, 2022, 9:36pm UTC](https://www.isharkfly.com/t/spring-boot/14069 "2022-08-24T21:36:58Z")

</div>

提示的错误信息为： Caused by: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.apache.logging.slf4…

---

## [Spring Boot 进行测试的提示后提示没有配置上下文](https://www.isharkfly.com/t/spring-boot/14068)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [August 24, 2022, 8:16pm UTC](https://www.isharkfly.com/t/spring-boot/14068 "2022-08-24T20:16:06Z")

</div>

错误的提示信息如下： java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test 问题和解决 有关 Spring 项目的 Application 文件要放到项目的最上层…

---

## [Spring 项目启动错误提示 LoggingApplicationListener](https://www.isharkfly.com/t/spring-loggingapplicationlistener/14067)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [August 24, 2022, 8:11pm UTC](https://www.isharkfly.com/t/spring-loggingapplicationlistener/14067 "2022-08-24T20:11:02Z")

</div>

启动 Spring 项目的时候提示下面的错误信息： Exception in thread "main" java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.context.ApplicationListener : org.springframework.boot.context.logging.LoggingApp…

---

## [解决在 Spring Boot 中运行 JUnit 测试遇到的 NoSuchMethodError 错误](https://www.isharkfly.com/t/spring-boot-junit-nosuchmethoderror/14066)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [August 24, 2022, 6:34pm UTC](https://www.isharkfly.com/t/spring-boot-junit-nosuchmethoderror/14066 "2022-08-24T18:34:56Z")

</div>

在本文章中，我们将会解决在 Spring Boot 运行测试的时候，得到 NoSuchMethodError 和 NoClassDefFoundError 的 JUnit 错误。 这个错误的原因，通常是因为我们的系统中有 2 个不同的 JUnit 版本，在运行的时候 JUnit 不知道使用哪个版本来运行。 同时，也有可能是因为 JUnit 测试运行使用的的版本和框架运行的版本不同而导致的。 错误的界面如下 Spring …

---

## [Spring Controller 参数必需性设置技巧](https://www.isharkfly.com/t/spring-controller/16537)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 1\
**Last updated:** [October 31, 2024, 8:51pm UTC](https://www.isharkfly.com/t/spring-controller/16537 "2024-10-31T20:51:02Z")

</div>

Spring Controller 如何确定参数为必须的。

---

## [Spring HATEOAS 可以封装细节，提高可发现性，简化客户端](https://www.isharkfly.com/t/spring-hateoas/16475)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 1\
**Last updated:** [October 25, 2024, 2:57am UTC](https://www.isharkfly.com/t/spring-hateoas/16475 "2024-10-25T02:57:11Z")

</div>

Spring HATEOAS 能解决什么问题。 备注 Spring HATEOAS 是一个用于支持实现超文本驱动的 REST Web 服务的开发库。是 HATEOAS 的实现。 （HATEOAS背后的思想就是响应中包含指向其它资源的链接。客户端可以利用这些链接和服务器交互） 用土话来说，就是向 RETS 发送一个请求后，RETS 会更具后端的关联关系返回更多的接口。 例如： { "id" : 1, "body"…

---

## [Spring 项目启动提示无法创建 Bean 错误](https://www.isharkfly.com/t/spring-bean/16446)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [October 21, 2024, 12:05am UTC](https://www.isharkfly.com/t/spring-bean/16446 "2024-10-21T00:05:16Z")

</div>

最近项目升级到 Spring 3.3.x 后，提示下面的 JPA 错误： Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource \[org/springframework/boot/auto…

---

## [Java Spring 连接池的重要性](https://www.isharkfly.com/t/java-spring/16428)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [October 15, 2024, 6:49pm UTC](https://www.isharkfly.com/t/java-spring/16428 "2024-10-15T18:49:11Z")

</div>

如果不在 Spring 项目中设置连接池的话，默认还是会使用连接池。 但查看连接池的配置的时候可能会得不到想要的结果。 14:07:59.405 \[restartedMain\] DEBUG com.zaxxer.hikari.HikariConfig - keepaliveTime...................0 14:07:59.405 \[restartedMain\] DEBUG com.zaxxer.hikari.Hik…

---

## [Spring JPA 排序错误](https://www.isharkfly.com/t/spring-jpa/16425)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [October 15, 2024, 3:00am UTC](https://www.isharkfly.com/t/spring-jpa/16425 "2024-10-15T03:00:00Z")

</div>

最近再创建排序的时候出现下面的这个错误： Caused by: java.lang.ClassNotFoundException: org.springframework.cglib.proxy.NoOp at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) at java.base/java.lang.…

---

## [Spring JPA 3 typedef 被删除](https://www.isharkfly.com/t/spring-jpa-3-typedef/15811)

<div class="topic-metadata">

**Author:** [@hex](https://www.isharkfly.com/u/hex)\
**Replies:** 0\
**Last updated:** [May 30, 2024, 4:48am UTC](https://www.isharkfly.com/t/spring-jpa-3-typedef/15811 "2024-05-30T04:48:48Z")

</div>

JPA 升级到 3 后，typedef 被删除了，已经不能使用了。 可以使用 @Convert 来替代使用。 如下面的的代码： @Converts({ @Convert(attributeName = "string-array", converter = StringArrayType.class), @Convert(attributeName = "int-array", converter …

---

## [Spring Data 为什么需要 Specifications](https://www.isharkfly.com/t/spring-data-specifications/15810)

<div class="topic-metadata">

**Author:** [@hex](https://www.isharkfly.com/u/hex)\
**Replies:** 0\
**Last updated:** [May 30, 2024, 4:33am UTC](https://www.isharkfly.com/t/spring-data-specifications/15810 "2024-05-30T04:33:35Z")

</div>

在 Spring Boot 中执行查询的最常见方法之一是使用如下查询方法： interface ProductRepository extends JpaRepository\<Product, String\>, JpaSpecificationExecutor\<Product\> { List\<Product\> findAllByNameLike(String name); Li…

---

## [Spring Data 中的 Specifications](https://www.isharkfly.com/t/spring-data-specifications/15809)

<div class="topic-metadata">

**Author:** [@hex](https://www.isharkfly.com/u/hex)\
**Replies:** 0\
**Last updated:** [May 30, 2024, 4:31am UTC](https://www.isharkfly.com/t/spring-data-specifications/15809 "2024-05-30T04:31:18Z")

</div>

如果您正在寻找一种更好的方法来管理您的查询或想要生成动态和类型安全的查询，那么您可能会在 Spring Data JPA Specifications中找到您的解决方案。 什么是 Specifications Spring Data JPA Specifications 是我们可以使用的另一个工具，可以使用 Spring 或 Spring Boot 执行数据库查询。 Specifications 建立在 Criteria API 之…

---

## [Spring Boot 版本升级到 3 的 JPA](https://www.isharkfly.com/t/spring-boot-3-jpa/15808)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [May 30, 2024, 4:22am UTC](https://www.isharkfly.com/t/spring-boot-3-jpa/15808 "2024-05-30T04:22:42Z")

</div>

在 Spring Boot 2 的版本中，使用的是 javax 的 persistence API。 当升级到 Spring Boot 3 后，JPA 使用的是 jakarta 因此在 Spring Boot 升级到 2 的时候，有关的实体类都需要修改。 Maven 通过 Maven 的仓库依赖，我们也能够看到包的路径的修改。

---

## [Spring Batch 2 升级到 3 的 Autowired 错误](https://www.isharkfly.com/t/spring-batch-2-3-autowired/15805)

<div class="topic-metadata">

**Author:** [@hex](https://www.isharkfly.com/u/hex)\
**Replies:** 0\
**Last updated:** [May 28, 2024, 3:50am UTC](https://www.isharkfly.com/t/spring-batch-2-3-autowired/15805 "2024-05-28T03:50:37Z")

</div>

错误信息为： D:\\WorkDir\\iSharkFly\\USVisaTrack\\Source-Code\\Services\\Visa-Isharkfly-Service\\src\\main\\java\\com\\northtecom\\visatrack\\api\\jobs\\JobParamDemo.java:43:70 java: incompatible types: java.util.Map\<java.lang.String,org.sp…

---

## [ActiveMQ Artemis 集成 Spring 中的配置](https://www.isharkfly.com/t/activemq-artemis-spring/14991)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [September 19, 2023, 7:13pm UTC](https://www.isharkfly.com/t/activemq-artemis-spring/14991 "2023-09-19T19:13:06Z")

</div>

在 Spring 2 的版本下，有关 Artemis 的配置参数为： spring.artemis.mode=native spring.artemis.host=nas1120 spring.artemis.port=61616 spring.artemis.user=USERNAM spring.artemis.password=PASS 上面的配置已经在 Spring 3 的时候修改为： spring.activemq.br…

---

## [ActiveMQ Artemis 集成 Spring 测试](https://www.isharkfly.com/t/activemq-artemis-spring/14881)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [September 13, 2023, 6:10am UTC](https://www.isharkfly.com/t/activemq-artemis-spring/14881 "2023-09-13T06:10:37Z")

</div>

经过半天的折腾，终于把 ActiveMQ 部署到服务器上，并且设置了消息发送服务器。 通过调用 API 发送数据到 API 后将数据推送到消息服务器上。 使用的是 Spring Boot 的代码，并且集成了下面的依赖。 \<dependency\> \<groupId\>org.springframework.boot\</groupId\> \<artifactId\>spr…

---

## [Spring 的 IoC（控制反转）](https://www.isharkfly.com/t/spring-ioc/14391)

<div class="topic-metadata">

**Author:** [@lucas](https://www.isharkfly.com/u/lucas)\
**Replies:** 0\
**Last updated:** [April 22, 2023, 11:29am UTC](https://www.isharkfly.com/t/spring-ioc/14391 "2023-04-22T11:29:42Z")

</div>

IoC 是 Inversion of Control 的简写，译为“控制反转”，它不是一门技术，而是一种设计思想，也是一个概念，同时是一个重要的面向对象编程法则，能够指导我们如何设计出松耦合、更优良的程序。 在这里说 IoC 之前，你需要完全理解一个概念 DI（依赖注入）。 当你理解依赖注入以后，对控制反转就非常简单了，只是一个概念而已。 什么是依赖注入，请参考文章：Java 依赖注入（DI） 控制反转 用土话来说就是本来…

---

## [Spring 项目运行提示错误 Not a managed type](https://www.isharkfly.com/t/spring-not-a-managed-type/14368)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [March 31, 2023, 5:09pm UTC](https://www.isharkfly.com/t/spring-not-a-managed-type/14368 "2023-03-31T17:09:46Z")

</div>

在启动 Spring 项目的时候提示下面的错误信息。 问题和原因 这个问题的原因是你的类没有在 Spring 管理的容器中注册。 主要原因是上面的包的路径不正确。 修改上面的包的路径后重启服务就可以解决启动的时候对象没有注册的问题。

---

## [SpringBoot 使用 @ConfigurationProperties 异常 Not registered via @EnableConfigurationProperties](https://www.isharkfly.com/t/springboot-configurationproperties-not-registered-via-enableconfigurationproperties/14312)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [February 6, 2023, 2:44pm UTC](https://www.isharkfly.com/t/springboot-configurationproperties-not-registered-via-enableconfigurationproperties/14312 "2023-02-06T14:44:37Z")

</div>

最近，我们在使用 @ConfigurationProperties 进行注解的时候，遇到了 Not registered via @EnableConfigurationProperties, marked as Spring component, or scanned via @ConfigurationPropertiesScan 异常。 问题和解决 上面的问题的原因是：因为被注解的类没有进行实例化操作，比如没有使用@C…

---

## [介绍 Spring Data Redis](https://www.isharkfly.com/t/spring-data-redis/14299)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [January 19, 2023, 5:40pm UTC](https://www.isharkfly.com/t/spring-data-redis/14299 "2023-01-19T17:40:55Z")

</div>

概述 本文章主要对 Spring Data Redis 的使用进行一些说明。 主要涉及到如何在 Spring 数据平台上如何使用 Redis。如果你对什么是 Redis 还不太熟悉的话，请参考：Redis 简介 文章中的内容。 简单的来说 Redis 是一个内存使用的 K-V 数据库，我们主要用来进行数据存储。 同时 Redis 还可以对存储的数据进行持久化（把数据存储到硬盘上），通常被作为数据库，缓存或者消息数据来进行使用。 我…

---

## [Spring 属性文件的松散绑定（Relaxed Binding）](https://www.isharkfly.com/t/spring-relaxed-binding/14294)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [January 12, 2023, 3:07pm UTC](https://www.isharkfly.com/t/spring-relaxed-binding/14294 "2023-01-12T15:07:42Z")

</div>

针对属性文件中的变量，Spring 使用的是松散绑定（ Relaxed Binding） 根据官方的说明： 下面的绑定方式都能够正确的把值注入到变量中。 user.firstName // 标准驼峰命名语法 user.first-name // 短横线隔开表示，推荐用于.properties和.yml文件中 user.first\_name // 下划线表示，用于.properties和.yml文件的可选格式 USER\_FIR…

[Next page](https://www.isharkfly.com/tag/spring/10.md?match_all_tags=true&page=1&tags%5B%5D=spring)
