So aktivieren und konfigurieren Sie die Überwachung in einer Spring Boot-AnwendungJava

Java-Forum
Anonymous
 So aktivieren und konfigurieren Sie die Überwachung in einer Spring Boot-Anwendung

Post by Anonymous »

Ich habe diese Hauptklasse:

Code: Select all

@SpringBootApplication
@EnableScheduling
@ConfigurationPropertiesScan
@EnableJpaAuditing(auditorAwareRef = "auditorAwareImpl")
public class PlanetsApplication {

public static void main(String[] args) {

SpringApplication.run(PlanetsApplication.class, args);

}
}
und

Code: Select all

@Component("auditorAwareImpl")
public class AuditorAwareImpl implements AuditorAware {

@NotNull
@Override
public Optional getCurrentAuditor() {
return Optional.of("system");
}

}
und

Code: Select all

@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;

}
und

Code: Select all

@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

}
Ich speichere die Entität:

Code: Select all

SpotifyPlayList spotifyPlayList2 = spotifyPlayListService.findAll().stream().findAny().get();
spotifyPlayList2.setSun(spotifyPlayList2.getSun().toUpperCase());
spotifyPlayListService.save(spotifyPlayList2);

log.info("saved {} ", spotifyPlayList2);
aber in der Datenbank wird nichts geprüft

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post