问题标签 [spring-data-commons]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
1154 浏览

mysql - CrudRepository 如何处理来自 ConnectionPool 的数据库连接

我找不到 spring-data-commonscrudrepository接口的任何默认实现类。我们总是实现CustomRepository extends CrudRepository<T, ID>然后@Autowire CustomRepository customRepository在服务类中调用customRepository.save(s)..它总是有效的。

我想了解与任何 crudrepository 方法相关的低级细节,例如save(S)

  1. 何时打开或关闭与底层数据库的连接?
  2. 事务边界是如何定义的?
  3. 它如何与连接池一起使用?

    任何指向正确资源的指针都会非常有帮助。如果我遗漏了一些愚蠢的东西,请随时指出我......
0 投票
0 回答
783 浏览

spring-boot - Spring Data REST / Spring Data Commons 域事件

我阅读了此博客和此参考资料,并确定在 Spring Data REST AbstractRepositoryEventListener 事件(即 onBeforeSave、onAfterDelete 等)中应用 Spring Data Commons Domain Events 时不起作用。

人:

人员已完成事件:

更新:阅读 PersonH​​andler 中的注释,这就是为什么应用程序事件在此示例中不起作用的原因。

人员处理程序:

抽象实体:

个人监听器:

我已经对此进行了广泛的调试,看起来 DomainEvents 被丢弃在RepositoryEntityControllerEventPublishingRepositoryProxyPostProcessor$EventPublishingMethodInterceptor之间的某个地方。

真正发生的是,我的 Entity 的另一个实例实际上被拦截了,此时 DomainEvents 不再存在。我可以确认此时没有调用 @AfterDomainEventPublication clearDomainEvents(),这让我相信它与 domainEvents 暂时性有关。

Spring Data REST 的RepositoryEntityController如下所示:

在执行注释为 1 的行后,我的 domainObject 具有 domainEvents,这就是注释为 2 的行中的内容,invokeSave。当我的断点在RepositoryEntityControllerEventPublishingRepositoryProxyPostProcessor$EventPublishingMethodInterceptor捕获时,它实际上是我的对象的不同实例(不同的对象 id),唯一缺少的是 domainEvents 并且没有任何东西被触发。

更新:阅读下面我的评论,它不起作用,因为实体已分离。

0 投票
0 回答
389 浏览

spring-data-elasticsearch - spring data elasticsearch 3.0.0 和 spring data commons

我正在使用 spring data elasticsearch 快照版本(3.0.0.BUILD-SNAPSHOT)

如果我使用 ElasticsearchTemplate,我会收到错误消息:

java.lang.NoSuchMethodError: org.springframework.util.Assert.isTrue(ZLjava/util/function/Supplier;)V

因为在 spring-data-commons-2.0.0BUILD-SANPSHOT & spring-data-elasticsearch-3.0.0.BUILD-SNAPSHOT 中,调用 org.springframework.util.Assert.isTrue(ZLjava/util/function/Supplier;)V !

但是springframwork 4.3.10-REALEASE中没有这样的方法:(

我该如何解决这种碰撞?

0 投票
3 回答
585 浏览

spring-boot - 未声明依赖项导致的错误

有没有人成功让 Spring Boot、Spring Data Elasticsearch 和 Elasticsearch 5.x 工作?

我更新了我的 pom 以使用 spring-data-elasticsearch 3.0.0.RELEASE(刚刚发布),它在 Github 中有提交说明,说它支持 ES 5。

我遇到了一些错误,这些错误是由于没有声明对spring-data-common. 在没有版本的情况下添加后,我注意到它显然是由 Spring Boot 管理的,并且引入了 1.13.7.RELEASE

这引起:java.lang.NoClassDefFoundError: org/springframework/data/mapping/model/Property

然后我升级spring-data-common到 2.0.0.RELEASE,认为所有东西的最新版本都应该兼容。当存储库连接时,这会导致 AbstractMethodError 异常。

任何人都可以提供任何提示吗?这是我的 POM 的依赖项

0 投票
0 回答
1372 浏览

java - 启动 spring-boot 应用程序时出现 StackOverflowError

在我的 spring-boot maven 项目中,依赖项之一是带来spring-data-commons. 这会扫描我项目中的类并引发 StackOverflow 错误。它不喜欢的课程如下,

我想它正在字段上尝试一些反射机制,随后由于一些不确定的循环而失败。spring-boot 应用程序启动期间的日志。

我不希望它扫描这个类(或任何类)。我只是删除spring-data-commons. 因为它在我的应用程序的其他部分中用于注入一些会话对象。

有什么建议可以解决这个问题吗?

PS:我不是弹簧数据方面的专家。但是已经使用弹簧很长一段时间了。

干杯!

0 投票
1 回答
3284 浏览

maven - 不兼容的 Spring 依赖项(调用 AnnotationRepositoryConfigurationSource 构造函数时出现 NoSuchMethodError)

添加持久性后,我无法再启动我的 Spring Boot 应用程序。错误是:

我将其追溯到AnnotationRepositoryConfigurationSource所在的spring-data-commons中的更改,并且在版本 1.13.5 中添加了一个额外的构造函数参数,并且spring-boot-starter-data应该使用具有相同构造函数签名的版本 1.13.7 -jpa在版本 1.5.7 中。而且我们只使用版本号为 1.5.7 的 Spring Boot 依赖项。

于是我构建了依赖树,奇怪的是在 1.13.4 版本中找到了spring-data-commons,而不是 1.13.7(倒数第三行):

上树你可以看到spring-data-jpa包含在 1.11.4 版本中,而根据Spring Boot Dependency Annex,它应该是 1.11.7 版本。这似乎导致了错误。但是我们不直接通过我们的 pom 文件依赖spring-data-jpa 。

所以我不知道这个旧版本是如何进入依赖树的。spring-boot-starter-data-jpa的 pom不表示任何版本号。

0 投票
1 回答
492 浏览

java - OrderBy results in error with older Spring Data

I wanted to write a method that returns a paged and sorted list of entities, and I was hoping that Spring Data can derive the query from the method name directly. The following repository definition from a shared module works well when used in one module and fails with "Context initialization failed" error when used in another.

The first module is newer and it depends on Spring Data JPA 1.11.0 + Spring Data Commons 1.13.0. The second module is older and it depends on Spring Data JPA 1.6.2 + Spring Data Commons 1.8.2.

Here's a piece of logs:

How to rewrite this method so it works in all versions of Spring Data without errors?

0 投票
1 回答
57 浏览

spring - spring data - 在自定义默认存储库实现中获取 bean

我试图将我的项目从升级spring-boot-1.4.3.RELEASEspring-boot-1.5.9.RELEASE.

1.4.3.RELEASE我使用存储库的自定义实现的方式如下:

  1. 制作了一个MyCustomRepositroy扩展的接口JpaRepository
  2. 有一个MyCustomRepositoryImpl实现MyCustomRepositroy和的类SimpleJpaRepository。在那个类中,我改变了
    of和方法的行为save,因为我需要 特定类型的实体的特定行为(假设我需要为所有实现接口的实体自定义)finddelete
    saveSpecial
  3. 我做了一个MyCustomJpaRepositoryFactoryBean延伸的JpaRepositoryFactoryBean。在那个工厂,我已经重写createRepositoryFactory并给了它我的MyRepositoryFactory实现。在MyRepositoryFactory实现中,我覆盖了getTargetRepository, 和getRepositoryBaseClass. 在这些方法中,我检查实体是否属于 type Special,如果是,则返回MyCustomRepositoryImpl,否则返回SimpleJpaRepository

此外,我可以在我的MyCustomRepositoryImpl类中获取 beanFactory,因为我调用我自己的构造函数,MyCustomRepositoryImpl它也有一个 beanFactory 参数 via getTargetRepositoryViaReflection

现在,使用新版本(使用spring-data-commons-1.13.9.RELEASE),我无法覆盖 Factory 类,因此无法为每个实体决定要提供哪个实现,也无法获取 beanFactory。

有什么办法可以得到我想要的吗?

对不起,我不能在这里发布我的代码。

PS - 我的项目是一个基于弹簧的库,所以我不能对实体做任何事情,因为我的客户声明了它们,我只知道有些实体实现了Special接口,有些没有

0 投票
2 回答
7270 浏览

spring-data - Spring Data Page 未正确将排序序列化为 JSON

此问题出现在 Spring-Data 版本 2 中。在最新版本 1.13.9(及更早版本)中,它运行良好。

控制器代码:

Spring-Data 2 风格相同:

配置:

还尝试了简单的 Spring 应用程序,没有 Spring Boot 和 Java 配置以及 XML 配置。结果是一样的:

如果我将 Spring-Data 版本更改为 1.X,我将得到正确的 JSON 响应来排序对象:

似乎我什么都试过了,我没有在更新日志中找到任何关于排序更改的通知,我在 Spring JIRA 中没有发现这样的问题。

所以问题是我如何使用 spring-data 2.X libs JSON 排序如下:

代替:

0 投票
1 回答
223 浏览

java - 将 Spring Data Commons 用于 Page.map 方法时出现异常

我在执行 jar 时遇到异常:

(Lorg/springframework/core/type/AnnotationMetadata;Ljava/lang/Class;Lorg/springframework/core/io/ResourceLoader;Lorg/springframework/core/env/Environment;)V

我在 pom.xml 中添加了以下依赖项:

父母为: