简体   繁体   中英

Spring Data MongoDB how to set index ttl from system property

Preferably, using the @Indexed annotation, or some other declarative way, is it possible to inject a system property, preferably using SPeL.

I have tried the following but found expireAfterSeconds gives error because it wants an int:

@Data
@Document(collection = "#{@xyzUpdates.collectionName}")
public class UpdatesFromXyz {

    @Id
    @Field("resourceId")
    private UUID resourceId;

    @Indexed(expireAfterSeconds = "#{@xyzUpdates.maxRecords}")
    private LocalDate updateDate;

}

and my properties class:

@ConfigurationProperties("xyz.updates")
@Getter
@Setter
@Component
public class XyzUpdates {

    private String collectionName = "updatesFromXyz";
    private int maxRecords;
}

从 SpringData MongoDB 2.2 开始,您可以使用expireAfter接受数字值,后跟它们的度量单位或 Spring 模板表达式。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM