Программисты JAVA общаются здесь
Anonymous
Как включить и настроить аудит в приложении Spring Boot
Сообщение
Anonymous » 17 янв 2025, 13:03
У меня есть основной класс:
Код: Выделить всё
@SpringBootApplication
@EnableScheduling
@ConfigurationPropertiesScan
@EnableJpaAuditing(auditorAwareRef = "auditorAwareImpl")
public class PlanetsApplication {
public static void main(String[] args) {
SpringApplication.run(PlanetsApplication.class, args);
}
}
и
Код: Выделить всё
@Component("auditorAwareImpl")
public class AuditorAwareImpl implements AuditorAware {
@NotNull
@Override
public Optional getCurrentAuditor() {
return Optional.of("system");
}
}
и
Код: Выделить всё
@Getter
@Setter
@EntityListeners(AuditingEntityListener.class)
@MappedSuperclass
public class BaseEntity {
@CreatedDate
@Column(updatable = false)
protected LocalDateTime createdAt;
@CreatedBy
@Column(updatable = false)
private String createdBy;
@LastModifiedDate
@Column(updatable = false)
protected LocalDateTime updatedAt;
@LastModifiedBy
@Column(updatable = false)
protected String updatedBy;
}
и
Код: Выделить всё
@Entity
@Table(name = "t_spotify_playlist", uniqueConstraints =
@UniqueConstraint(columnNames = {"playlistId", "sun", "moon"}))
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class SpotifyPlayList extends BaseEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String playlistId;
@Column(length = 50)
private String sun;
@Column(length = 50)
private String moon;
// Many-to-Many relationship with SpotifyTrack
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "t_playlist_track", // Join table name
joinColumns = @JoinColumn(name = "playlist_id"), // Foreign key for SpotifyPlayListDesc
inverseJoinColumns = @JoinColumn(name = "track_id") // Foreign key for SpotifyTrack
)
private Set tracks; // Tracks associated with the playlist
}
Я сохраняю объект:
Код: Выделить всё
SpotifyPlayList spotifyPlayList2 = spotifyPlayListService.findAll().stream().findAny().get();
spotifyPlayList2.setSun(spotifyPlayList2.getSun().toUpperCase());
spotifyPlayListService.save(spotifyPlayList2);
log.info("saved {} ", spotifyPlayList2);
но в БД ничего не проверяется
Подробнее здесь:
https://stackoverflow.com/questions/793 ... pplication
1737108227
Anonymous
У меня есть основной класс: [code]@SpringBootApplication @EnableScheduling @ConfigurationPropertiesScan @EnableJpaAuditing(auditorAwareRef = "auditorAwareImpl") public class PlanetsApplication { public static void main(String[] args) { SpringApplication.run(PlanetsApplication.class, args); } } [/code] и [code]@Component("auditorAwareImpl") public class AuditorAwareImpl implements AuditorAware { @NotNull @Override public Optional getCurrentAuditor() { return Optional.of("system"); } } [/code] и [code]@Getter @Setter @EntityListeners(AuditingEntityListener.class) @MappedSuperclass public class BaseEntity { @CreatedDate @Column(updatable = false) protected LocalDateTime createdAt; @CreatedBy @Column(updatable = false) private String createdBy; @LastModifiedDate @Column(updatable = false) protected LocalDateTime updatedAt; @LastModifiedBy @Column(updatable = false) protected String updatedBy; } [/code] и [code]@Entity @Table(name = "t_spotify_playlist", uniqueConstraints = @UniqueConstraint(columnNames = {"playlistId", "sun", "moon"})) @Getter @Setter @AllArgsConstructor @NoArgsConstructor @Builder public class SpotifyPlayList extends BaseEntity implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String playlistId; @Column(length = 50) private String sun; @Column(length = 50) private String moon; // Many-to-Many relationship with SpotifyTrack @ManyToMany(fetch = FetchType.EAGER) @JoinTable( name = "t_playlist_track", // Join table name joinColumns = @JoinColumn(name = "playlist_id"), // Foreign key for SpotifyPlayListDesc inverseJoinColumns = @JoinColumn(name = "track_id") // Foreign key for SpotifyTrack ) private Set tracks; // Tracks associated with the playlist } [/code] Я сохраняю объект: [code]SpotifyPlayList spotifyPlayList2 = spotifyPlayListService.findAll().stream().findAny().get(); spotifyPlayList2.setSun(spotifyPlayList2.getSun().toUpperCase()); spotifyPlayListService.save(spotifyPlayList2); log.info("saved {} ", spotifyPlayList2); [/code] но в БД ничего не проверяется Подробнее здесь: [url]https://stackoverflow.com/questions/79364218/how-to-enable-and-configure-auditing-in-a-spring-boot-application[/url]
Как включить и настроить аудит в приложении Spring Boot
Anonymous »
17 янв 2025, 14:07 » в форуме
JAVA
У меня есть основной класс:
@SpringBootApplication
@EnableScheduling
@ConfigurationPropertiesScan
@EnableJpaAuditing(auditorAwareRef = auditorAwareImpl )
public class PlanetsApplication {
public static void main(String[] args) {...
0 Ответы
7 Просмотры
Последнее сообщение Anonymous
17 янв 2025, 14:07
Как включить и настроить аудит в приложении Spring Boot
Anonymous »
17 янв 2025, 16:02 » в форуме
JAVA
У меня есть основной класс:
@SpringBootApplication
@EnableScheduling
@ConfigurationPropertiesScan
@EnableJpaAuditing(auditorAwareRef = auditorAwareImpl )
public class PlanetsApplication {
public static void main(String[] args) {...
0 Ответы
14 Просмотры
Последнее сообщение Anonymous
17 янв 2025, 16:02
Как включить и настроить аудит в приложении Spring Boot
Anonymous »
23 янв 2025, 19:11 » в форуме
JAVA
У меня есть основной класс:
@SpringBootApplication
@EnableScheduling
@ConfigurationPropertiesScan
@EnableJpaAuditing(auditorAwareRef = auditorAwareImpl )
public class PlanetsApplication {
public static void main(String[] args) {...
0 Ответы
17 Просмотры
Последнее сообщение Anonymous
23 янв 2025, 19:11
Как включить и настроить аудит в приложении Spring Boot
Гость »
23 янв 2025, 21:03 » в форуме
JAVA
У меня есть основной класс:
@SpringBootApplication
@EnableScheduling
@ConfigurationPropertiesScan
@EnableJpaAuditing(auditorAwareRef = auditorAwareImpl )
public class PlanetsApplication {
public static void main(String[] args) {...
0 Ответы
16 Просмотры
Последнее сообщение Гость
23 янв 2025, 21:03
Аудит в Spring Boot
Anonymous »
17 янв 2025, 12:13 » в форуме
JAVA
У меня есть основной класс:
@SpringBootApplication
@EnableScheduling
@ConfigurationPropertiesScan
@EnableJpaAuditing(auditorAwareRef = auditorAwareImpl )
public class PlanetsApplication {
public static void main(String[] args) {...
0 Ответы
13 Просмотры
Последнее сообщение Anonymous
17 янв 2025, 12:13