<legend id='cuVvi'><style id='cuVvi'><dir id='cuVvi'><q id='cuVvi'></q></dir></style></legend>
    • <bdo id='cuVvi'></bdo><ul id='cuVvi'></ul>

        <tfoot id='cuVvi'></tfoot>
        <i id='cuVvi'><tr id='cuVvi'><dt id='cuVvi'><q id='cuVvi'><span id='cuVvi'><b id='cuVvi'><form id='cuVvi'><ins id='cuVvi'></ins><ul id='cuVvi'></ul><sub id='cuVvi'></sub></form><legend id='cuVvi'></legend><bdo id='cuVvi'><pre id='cuVvi'><center id='cuVvi'></center></pre></bdo></b><th id='cuVvi'></th></span></q></dt></tr></i><div id='cuVvi'><tfoot id='cuVvi'></tfoot><dl id='cuVvi'><fieldset id='cuVvi'></fieldset></dl></div>
      1. <small id='cuVvi'></small><noframes id='cuVvi'>

        为什么没有使用 Spring Data JPA 设置版本属性?

        Why is the version property not set with Spring Data JPA?(为什么没有使用 Spring Data JPA 设置版本属性?)

        <small id='dITrg'></small><noframes id='dITrg'>

          • <bdo id='dITrg'></bdo><ul id='dITrg'></ul>
              <tfoot id='dITrg'></tfoot>
                <tbody id='dITrg'></tbody>

                  <i id='dITrg'><tr id='dITrg'><dt id='dITrg'><q id='dITrg'><span id='dITrg'><b id='dITrg'><form id='dITrg'><ins id='dITrg'></ins><ul id='dITrg'></ul><sub id='dITrg'></sub></form><legend id='dITrg'></legend><bdo id='dITrg'><pre id='dITrg'><center id='dITrg'></center></pre></bdo></b><th id='dITrg'></th></span></q></dt></tr></i><div id='dITrg'><tfoot id='dITrg'></tfoot><dl id='dITrg'><fieldset id='dITrg'></fieldset></dl></div>

                  <legend id='dITrg'><style id='dITrg'><dir id='dITrg'><q id='dITrg'></q></dir></style></legend>
                • 本文介绍了为什么没有使用 Spring Data JPA 设置版本属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  想知道 Spring Data REST 中的 @Version 注释是如何用于 ETags 的,但由于某种原因我没有看到 ETags 填充

                  Wanted to know how is @Version annotation in Spring Data REST put to use for ETags, I do not see the ETags populated for some reason

                  @Entity
                  @EntityListeners(AuditingEntityListener.class)
                  public class Venue implements Serializable {
                  
                    private static final long serialVersionUID = -5516160437873476233L;
                  
                    private Long id;
                  
                    ...
                    // other properties
                  
                    private Long version;
                  
                    private Date lastModifiedDate;
                  
                    // getters & setters
                  
                    @JsonIgnore
                    @LastModifiedDate
                    public Date getLastModifiedDate() {
                      return lastModifiedDate;
                    }
                  
                    @Version
                    @Column
                    public Long getVersion() {
                      return version;
                    }
                  

                  按照文档,这应该会给我一个 Etag 值吗?如库中的片段所示

                  Going by the docs this should give me an Etag Value? as seen in the snippet from the library

                  protected HttpHeaders prepareHeaders(PersistentEntity<?, ?> entity, Object value) {
                  
                      // Add ETag
                      HttpHeaders headers = ETag.from(entity, value).addTo(new HttpHeaders());
                  
                      // Add Last-Modified
                      AuditableBeanWrapper wrapper = getAuditableBeanWrapper(value);
                  

                  但是,给定实体 &以下配置,我仍然得到一个空版本.我的应用程序有以下

                  however, given the entity & following configuration, I still get a null for Version. My Application has the following

                  @SpringBootApplication
                  @EnableEntityLinks
                  @EnableJpaAuditing
                  public class GabbarSinghApplication
                  

                  而Rest Repository如下

                  And the Rest Repository is as follows

                  @RepositoryRestResource(collectionResourceRel = "venue", path = "venues")
                  public interface VenueRepository extends JpaRepository<Venue, Long> {
                  

                  虽然我还没有使用标题等测试这些方法,但在 http://localhost:8080/workshops 上的简单 POST 请求会给出 500因为从版本属性的值获取 ETag 标头值时出现空指针异常.

                  While I haven't got to test these methods yet with the headers etc, a simple POST request on http://localhost:8080/workshops gives a 500 because of null pointer exception at getting ETag header value from value of version property.

                  更新

                  实体已移至 @javax.persistence.Version,但我仍然没有在响应标头中获得 ETag 标头.

                  Moved to @javax.persistence.Version for the entities, I still do not get an ETag header in the response headers.

                  这是一个失败的单元测试

                  Here's a failing unit test

                    @Before
                    public void setUp() throws Exception {
                  
                      XStream xstream = new XStream();
                      ObjectInputStream in = xstream.createObjectInputStream(venuesXml.getInputStream());
                      leela = (Venue) in.readObject();
                      paul = (Venue) in.readObject();
                      taj = (Venue) in.readObject();
                      LOGGER.debug("Initialised Venues from xml file {}", venuesXml.getFilename());
                  
                    }
                  
                    @Test
                    public void testEtagHeaderIsAutoGeneratedOnResourceCreation() {
                  
                      final HttpEntity<Venue> httpEntity = new HttpEntity<Venue>(taj, headers);
                  
                      ResponseEntity<ResourceSupport> response = restTemplate.exchange(BASE_LOCATION
                          + VENUES_ENDPOINT, HttpMethod.POST, httpEntity,
                          new ParameterizedTypeReference<ResourceSupport>() {
                          });
                  
                      assertTrue("Response should contain ETag header", null != response.getHeaders().getETag());
                  

                  此断言失败.

                  推荐答案

                  我遇到了同样的问题,经过几个小时后,我意识到了以下导致我启蒙的事情 =P

                  I faced the same problem and after hours and hours I realized the following things that led me to the enlightenment =P

                  1. Spring Data Rest 仅在 2.3.0 版本之后为乐观并发控制提供 ETag 支持.请参阅大约一年前发布的此错误.以前版本的 Spring Data Rest 不会填充 ETag 标头.
                  2. 对于 Spring Boot 应用程序(我们的案例),您需要使用 Spring Boot 1.3.0.BUILD-SNAPSHOT 或更高版本才能设置依赖于 Spring Data Rest 的 spring-boot-starter-data-rest2.4.1(高于 2.3.1,这正是我们所需要的:P).
                  1. Spring Data Rest provides ETag support for optimistic concurrency control ONLY after version 2.3.0. See this bug published about a year ago. Previous versions of Spring Data Rest will NOT populate the ETag header.
                  2. For Spring Boot applications (our case), you need to use Spring Boot 1.3.0.BUILD-SNAPSHOT or higher in order to be able to setup a spring-boot-starter-data-rest that depends on Spring Data Rest 2.4.1 (higher than 2.3.1 which is exactly what we need :P).

                  在我的情况下,我使用的是 Spring Boot 1.2.7,每当我安装 spring-boot-starter-data-rest 依赖项时,我最终都会得到不支持 ETag 的 Spring Data Rest 2.2.0.在我的项目中升级 Spring Boot 并重新安装依赖项后,我的 REST API 开始检索 ETag 标头 =D

                  In my case I was using Spring Boot 1.2.7 and whenever I installed the spring-boot-starter-data-rest dependency I ended up getting the Spring Data Rest 2.2.0 which don't has the ETag support. After upgrading Spring Boot in my project and reinstalled the dependencies my REST API started to retrieve the ETag header =D

                  这篇关于为什么没有使用 Spring Data JPA 设置版本属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                  <legend id='Ziqkn'><style id='Ziqkn'><dir id='Ziqkn'><q id='Ziqkn'></q></dir></style></legend>

                  <small id='Ziqkn'></small><noframes id='Ziqkn'>

                    <bdo id='Ziqkn'></bdo><ul id='Ziqkn'></ul>
                      <tbody id='Ziqkn'></tbody>

                        <i id='Ziqkn'><tr id='Ziqkn'><dt id='Ziqkn'><q id='Ziqkn'><span id='Ziqkn'><b id='Ziqkn'><form id='Ziqkn'><ins id='Ziqkn'></ins><ul id='Ziqkn'></ul><sub id='Ziqkn'></sub></form><legend id='Ziqkn'></legend><bdo id='Ziqkn'><pre id='Ziqkn'><center id='Ziqkn'></center></pre></bdo></b><th id='Ziqkn'></th></span></q></dt></tr></i><div id='Ziqkn'><tfoot id='Ziqkn'></tfoot><dl id='Ziqkn'><fieldset id='Ziqkn'></fieldset></dl></div>
                            <tfoot id='Ziqkn'></tfoot>